Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] async and .await chapter #3909

Draft
wants to merge 191 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
0ec7296
Create crate for The Rust Programming Language
chriskrycho Apr 24, 2024
fcd470c
Add Tokio dependency
chriskrycho Apr 24, 2024
3943e51
Re-export `tokio::main` as `trpl::async_main` and test it.
chriskrycho Apr 24, 2024
e518289
Add more crate-level docs and matching README materials.
chriskrycho Apr 24, 2024
608c35b
Document the first test so people can understand it.
chriskrycho Apr 24, 2024
71ea12e
Add CI for `main` and PRs against `main`
chriskrycho Apr 24, 2024
4255d87
Add a CI status badge
chriskrycho Apr 24, 2024
7c40849
Add new Chapter 17: Async and Await
chriskrycho Apr 16, 2024
c1a0d14
Ch. 17: introduction section
chriskrycho Apr 16, 2024
d17c712
Ch. 17: Expand introduction and add stub for tasks chapter
chriskrycho Apr 19, 2024
4ce722d
Ch. 17: Fix a couple typos and incomplete sentences
chriskrycho Apr 19, 2024
71d92ec
Ch. 17: Add some introductory material about async/await
chriskrycho Apr 22, 2024
fdb3794
Ch. 17: Introduce runtimes and the `trpl` crate
chriskrycho Apr 23, 2024
cf00f05
Use “asynchronous programming” or “async”, not “async-await”
chriskrycho May 1, 2024
02b0bd1
Add note about Async Book ch. 4: Pinning
chriskrycho May 1, 2024
94d95c6
Ch. 17: Explain what `Poll::Pending` and `Poll::Ready(T)` mean.
chriskrycho May 1, 2024
b4bcb2c
Ch. 17: add a TODO for the `async fn` desugaring
chriskrycho May 1, 2024
63baf22
Ch. 17: fix a misplaced period
chriskrycho May 1, 2024
c31d308
Ch. 17: get to working async code sooner
chriskrycho May 1, 2024
0721b04
Merge `main` into `only-new-async`
chriskrycho May 9, 2024
dee7220
Ch. 17: add to table of contents so `mdbook serve` is useful
chriskrycho May 9, 2024
5b3c27e
Ch. 17: clarify language about Tokio
chriskrycho May 9, 2024
ebebf8c
Ch. 17: use `trpl`, not `futures`, even for initial code samples
chriskrycho May 9, 2024
ee0704d
Ch. 17: text/code ordering fix in 17.02
chriskrycho May 9, 2024
40df049
Prepare to integrate into TRPL repo
chriskrycho Apr 24, 2024
a150365
Ch. 17: merge in trpl crate
chriskrycho May 9, 2024
45bda34
Merge `main` into `only-new-async`
chriskrycho May 10, 2024
8f6bcc7
Ch. 17: expand, clarify, and restructure 17.01
chriskrycho May 10, 2024
0c00b17
Ch. 17: reorganize 17.01 and get a useable intro to Future
chriskrycho May 10, 2024
23027cb
Ch. 17: wording and formatting in 17.01
chriskrycho May 10, 2024
3cf4fae
Ch. 17: corrections/discussion on runtimes, mostly
chriskrycho May 10, 2024
c3ebabe
Ch. 17: pull disconnected material out of 17.01
chriskrycho May 10, 2024
5657a49
Ch. 17: minor wording improvement
chriskrycho May 10, 2024
dbd5e14
Ch. 17: use `Listing` for all existing listings
chriskrycho May 14, 2024
b4e3030
Ch. 17: eliminate duplicate runtime description
chriskrycho May 14, 2024
96fd725
Merge `main` into `only-new-async`
chriskrycho May 14, 2024
95105d2
Ch. 17: Add `futures` to `trpl` crate for re-exports
chriskrycho May 14, 2024
f418ceb
Ch. 17: abandon attempt to re-export `tokio::main`
chriskrycho May 14, 2024
8e7420e
Ch. 17: start in earnest on §2, showing relation to threads
chriskrycho May 14, 2024
1ee7975
Ch. 17: add more examples and explanation to §02.
chriskrycho May 15, 2024
9c1f4c8
Ch. 17: Finish 'Counting', start on 'Async Move Blocks'
chriskrycho May 15, 2024
dacddb5
Merge `main` into `only-new-async`
chriskrycho May 16, 2024
c1c3c7f
Ch. 17: start on message-passing and `async move` in §2
chriskrycho May 16, 2024
4b7886e
Ch. 17: Finish a pass on Message Passing example
chriskrycho May 17, 2024
b835c07
Merge `main` into `only-new-async`
chriskrycho May 22, 2024
5e09f02
Merge `main` into `only-new-async`
chriskrycho May 22, 2024
5483299
Exclude `trpl` from workspace
chriskrycho May 22, 2024
acde825
Ch. 17: skip `main` and `trpl::block_on` in some listings
chriskrycho May 22, 2024
7b14d7d
Ch. 17: inline some note content and fix some phrasing
chriskrycho May 22, 2024
89b3b25
Merge `main` into `only-new-async`
chriskrycho May 22, 2024
1d7c987
Ch. 17: Rewrite listings to be more similar to Ch. 16
chriskrycho May 22, 2024
1db4ee2
Ch. 17: wording and structure tweaks
chriskrycho May 22, 2024
af18d2b
Ch. 17: show multiple producers working with `clone`
chriskrycho May 22, 2024
b3fe5b7
Merge `main` into `only-new-async`
chriskrycho May 23, 2024
c1847bf
Ch. 17: restructure §00 and start better motivating async
chriskrycho May 23, 2024
1010b1f
Ch. 17: further motivation for async w/examples
chriskrycho May 24, 2024
8ce6c8a
Ch. 17: rework §00 to talk about reads instead of writes
chriskrycho May 24, 2024
52bf9e4
Ch. 17: extract parallelism discussion from §00 to §03
chriskrycho May 24, 2024
3224ceb
Ch. 17: dedicate §03 to 'Futures, Tasks, and Threads'
chriskrycho May 27, 2024
82f47c3
Ch. 17: Listings are all `17-*`!
chriskrycho May 27, 2024
91ffec8
Ch. 17: Fill out message-passing example
chriskrycho May 27, 2024
d3d7c64
Merge `main` into `only-new-async`
chriskrycho May 27, 2024
91348ca
Ch. 17: A minor wording improvement
chriskrycho May 27, 2024
068f30b
Ch 17.02: motivating `futures::join!` and `Box::pin`
chriskrycho May 27, 2024
7a5bdb2
Ch. 17: finish motivating `Pin` and `pin!`
chriskrycho May 28, 2024
626aec8
Ch. 17: A small wording tweak about `JoinAll` in §03
chriskrycho May 28, 2024
40a3dc1
Merge `main` into `only-new-async`
chriskrycho May 28, 2024
b382767
Ch. 17: Start building out explanation of `Pin`
chriskrycho May 28, 2024
e000ea3
Ch. 17: Iterate on explanation of `Pin` and `Unpin`
chriskrycho May 29, 2024
0032e07
Ch. 17: iterate on §02 examples, extract “extra” material
chriskrycho May 29, 2024
4236371
Ch. 17: Explain `join!` in §02
chriskrycho May 30, 2024
97f5bcc
Ch. 17 §02: Clarify the `move` discussion
chriskrycho May 30, 2024
888a519
Merge `main` into `only-new-async`
chriskrycho May 30, 2024
c6965ca
Ch. 17 §02: Start showing timeouts
chriskrycho May 30, 2024
c58f943
Ch. 17 §02: Start on example of select.
chriskrycho May 30, 2024
7da440a
Ch. 17 §02: Implement `timeout` example and building blocks
chriskrycho Jun 5, 2024
270780a
Ch. 17: build a `retry` implementation
chriskrycho Jun 5, 2024
1c27c97
Ch. 17: Drop material about `retry`, since it is a hazard
chriskrycho Jun 5, 2024
71acd6d
Ch. 17 §02: Write about `race` and `yield_now`
chriskrycho Jun 5, 2024
5a0fb42
Ch. 17: Split the over-long §02 into two parts
chriskrycho Jun 6, 2024
86835d6
Ch. 17: Show worked example of implementing `timeout`
chriskrycho Jun 6, 2024
a364865
Ch. 17 §04: Show perforance of `sleep` vs. `yield_now`
chriskrycho Jun 6, 2024
f4cd9d2
Ch. 17 §01: rephrase note about the details we don’t get into
chriskrycho Jun 7, 2024
b5010d1
Ch. 17 §01: Add necessary background for §04 to make sense
chriskrycho Jun 7, 2024
13adef4
Ch. 17 §04: Explain the *implications* of yielding to motivate it
chriskrycho Jun 7, 2024
54a18a7
Ch. 17 §04: explain yield better and rework examples
chriskrycho Jun 7, 2024
e56e906
Ch. 17 §04: Add a good transition sentence
chriskrycho Jun 7, 2024
95422ab
Ch. 17 §04: add a Note about cooperative multitasking
chriskrycho Jun 7, 2024
b3931ef
Ch. 17 §03: Add more explanatory material on `Pin`
chriskrycho Jun 7, 2024
8809d9f
Ch. 17: a better name for one of the internal sections
chriskrycho Jun 7, 2024
121f5b6
Ch. 17 §03: Explain pinning and `Deref` just enough
chriskrycho Jun 10, 2024
a97358e
Ch. 17 §03: Finish a first pass on explaining `Pin`
chriskrycho Jun 10, 2024
644bc54
Ch. 17 §04: Code sample and incomplete sentence fixes
chriskrycho Jun 10, 2024
b796ff8
Merge `main` into `only-new-async`
chriskrycho Jun 11, 2024
f786162
Ch. 17 §04: Give the section a reasonable title
chriskrycho Jun 11, 2024
39485b9
Merge `main` into `only-new-async`
chriskrycho Jun 12, 2024
617b755
Ch. 17: an editing pass on §00 and the start of §01
chriskrycho Jun 12, 2024
2360484
Ch. 17: reduce dependency list for `trpl` crate
chriskrycho Jun 12, 2024
5458a6a
Ch. 17: correct listing numbers for §01
chriskrycho Jun 12, 2024
217645e
Ch. 17 §01: flag a TODO item for later
chriskrycho Jun 12, 2024
c310f54
Ch. 17: Finish (first pass) documentation for `trpl::race`
chriskrycho Jun 12, 2024
69323d9
Ch. 17 §02: correct numbering and content for Listing 17-04
chriskrycho Jun 13, 2024
dc0ce20
Merge `main` into `only-new-async`
chriskrycho Jun 13, 2024
ccd6808
Ch. 17 §02: correct numbering and content for Listing 17-05
chriskrycho Jun 13, 2024
4c4ebb7
Ch. 17 §02: correct numbering and content for Listing 17-06
chriskrycho Jun 13, 2024
4c41d8f
Ch. 17 §02: remove listing that I split into multiple parts
chriskrycho Jun 13, 2024
6fd549d
Ch. 17 §02: correct numbering and content for Listing 17-07
chriskrycho Jun 13, 2024
bd26083
Ch. 17 §02: leave a TODO about one bucket of output
chriskrycho Jun 13, 2024
6d802a0
Ch. 17 §02: correct numbering and content for Listings 17-08 and 17-09
chriskrycho Jun 13, 2024
38ddc49
Ch. 17 §02: correct numbering and content for Listings 17-10 and 17-11
chriskrycho Jun 13, 2024
60cde00
Ch. 17 §02: correct numbering and content for Listing 17-12
chriskrycho Jun 13, 2024
7e5b6f2
Ch. 17 §02: correct numbering and content for Listings 17-13 and 17-14
chriskrycho Jun 13, 2024
766ad04
Ch. 17 §02: correct numbering and content for Listings 17-15 and 17-16
chriskrycho Jun 13, 2024
c308400
Ch. 17 §03: correct numbering and content for Listings 17-17
chriskrycho Jun 13, 2024
6035ba4
Ch. 17 §03: correct numbering and content for Listing 17-18
chriskrycho Jun 13, 2024
a1eb8ae
Ch. 17: Fix internal links
chriskrycho Jun 13, 2024
911167d
Ch. 17: Remove completed `TODO` for `Pin` 🎉
chriskrycho Jun 13, 2024
b8ecdb5
Ch. 17 §03: extract a no-listing for type mismatches
chriskrycho Jun 13, 2024
2b65e53
Ch. 17 §03: correct numbering and content for Listings 17-19 and 17-20
chriskrycho Jun 13, 2024
67bd0a0
Ch. 17 §03: support code for motivating `Pin`
chriskrycho Jun 13, 2024
686b3e4
Ch. 17 §03: add a TODO for checking Pin description correctness
chriskrycho Jun 13, 2024
91565da
Ch. 17 §03: correct listings and wording for `Pin` materials
chriskrycho Jun 13, 2024
fb683c9
Ch. 17 §03: correct listings and wording for first half of section
chriskrycho Jun 13, 2024
9d8f2c5
Ch. 17: renumber listings to eliminate `no-listing` listings
chriskrycho Jun 14, 2024
4f93e8b
Ch. 17: finish listing numbers for §04
chriskrycho Jun 14, 2024
d73e893
Merge `main` into `only-new-async`
chriskrycho Jun 14, 2024
4598e2c
Ch. 17 §01: make the conclusion section coherent
chriskrycho Jun 14, 2024
c0c24e2
Ch. 17 §02: transition for §03 and TODO cleanup
chriskrycho Jun 17, 2024
74df84e
Ch. 17: Add a new §05 on Stream and AsyncIterator
chriskrycho Jun 17, 2024
f0825ad
Ch. 17 S§02: introduce and explain `while let` syntax.
chriskrycho Jun 17, 2024
a05c34e
Ch. 17 §05: Introduce `Stream` and drop `AsyncIterator`
chriskrycho Jun 17, 2024
ad360d7
Ch 17. §01: leave a TODO about `IntoFuture`
chriskrycho Jun 18, 2024
52c516c
Ch. 17 §05: start explaining how we work with streams
chriskrycho Jun 18, 2024
e3ab302
Ch. 17: Remove a now-properly-numbered listing
chriskrycho Jun 19, 2024
cd1a3f7
Merge `main` into `only-new-async`
chriskrycho Jun 20, 2024
bf5e4aa
Ch. 17 (infra): add a base listing to use when generating new ones
chriskrycho Jun 19, 2024
e790c2c
Ch. 17: re-export `Stream`, `StreamExt`, and `stream_iter` in `trpl`
chriskrycho Jun 19, 2024
ce9b286
Ch. 17 §05: describe how to use `Stream`s with `Iterator`s
chriskrycho Jun 20, 2024
b4f5763
Ch. 17: final example for §05, with more re-exported streams
chriskrycho Jun 24, 2024
e71b667
Ch. 17 §05: First part of final example, with `ReceiverStream`
chriskrycho Jun 20, 2024
3c6c32c
Ch. 17 §05: complete example with `throttle` and `take`
chriskrycho Jun 25, 2024
bea8557
Ch. 17 §06: Start discussing future/task/thread tradeoffs
chriskrycho Jun 25, 2024
a8fe2d6
Merge `main` into `only-new-async`
chriskrycho Jun 26, 2024
bdd8f3e
Ch. 17 §06: more on tasks and threads, better example
chriskrycho Jun 26, 2024
ffb2d1b
Ch. 17: Most of §06 drafted, needs a conclusion
chriskrycho Jun 26, 2024
63214c3
Ch. 17 §00: rewrite the parallelism and concurrency section
chriskrycho Jun 26, 2024
6914bc4
Ch. 17 §00: no more cooks!
chriskrycho Jun 26, 2024
e774613
Ch. 17: remove 'base' listing
chriskrycho Jul 1, 2024
f039ca3
Ch. 17: Transition materials from Ch. 16 and into Ch. 18
chriskrycho Jun 27, 2024
5fdd92c
Ch. 17§00 initial edits
chriskrycho Jul 1, 2024
f023032
Ch. 17: add some more explanatory comments to `trpl`
chriskrycho Jul 1, 2024
eec1745
Ch. 17§01 initial edits for the first subsection
chriskrycho Jul 1, 2024
e238342
Ch. 17§01 initial edits for the second subsection
chriskrycho Jul 2, 2024
09b80f9
Ch. 17§02 initial edits on 'Counting'
chriskrycho Jul 2, 2024
e5c9afd
Ch. 17§02 initial edits on 'Message Passing'
chriskrycho Jul 2, 2024
89920d5
Ch. 17§03 Initial edits on opening section
chriskrycho Jul 3, 2024
451f77b
Ch. 17§03 initial edits on pinning section
chriskrycho Jul 3, 2024
1cc4dbe
Ch. 17§03: Rename the section for clarity
chriskrycho Jul 5, 2024
cc0f913
Ch. 17: remove now unused Listing 17-24
chriskrycho Jul 5, 2024
1030015
Ch. 17§04 initial edits on intro and “Yielding” section
chriskrycho Jul 5, 2024
ef1ed96
Ch. 17§04 initial edits on Building Our Own Async Abstractions
chriskrycho Jul 8, 2024
074c442
Ch. 17§05 initial edits on first two sections
chriskrycho Jul 9, 2024
1a90722
Merge `main` into `async-edits`
chriskrycho Jul 11, 2024
fbcdb24
Ch. 17§05 initial edits on 'Composing Streams'
chriskrycho Jul 11, 2024
2797d95
Ch. 17§05 initial edits on 'Merging Streams'
chriskrycho Jul 11, 2024
92c19ce
Ch. 17§06 initial edits
chriskrycho Jul 12, 2024
c3c88e4
Ch. 17 §03: restore accidentally-removed Listing 17-14
chriskrycho Jul 15, 2024
22b04c1
infra: prepare `trpl` crate for 0.1.0 release
chriskrycho Jul 16, 2024
58fff3c
Ch. 17§03: fix typo
chriskrycho Jul 16, 2024
130e6d0
Ch. 17: correct wrapping for a `Note`
chriskrycho Jul 16, 2024
dc8d7e8
Merge `main` into `async-edits`
chriskrycho Jul 17, 2024
bb9cdbb
Ch. 17: Update CI config to support testing the book with `trpl`
chriskrycho Jul 17, 2024
24ed6e4
Ch. 17§01: Make code/listings pass tests
chriskrycho Jul 17, 2024
deefe4d
Ch. 17§02: Make code/listings pass tests
chriskrycho Jul 17, 2024
6a0d072
Ch. 17§03: Make code/listings pass tests
chriskrycho Jul 17, 2024
0aacb80
Ch. 17§04: Make code/listings pass tests
chriskrycho Jul 17, 2024
40bdda7
Ch. 17§05: Make code/listings pass tests
chriskrycho Jul 17, 2024
5099e5f
Ch. 17§06: Make code listing pass tests and add a caption
chriskrycho Jul 17, 2024
45f1635
Ch. 17: fix spelling issues
chriskrycho Jul 22, 2024
463b819
Ch. 17: fix internal links with new ch. order
chriskrycho Jul 22, 2024
79fd5e2
Merge `main` into `async-edits`
chriskrycho Jul 22, 2024
644dbab
Ch. 17: fix an internal link reference
chriskrycho Jul 22, 2024
b2a2133
Merge `main` into `async-edits`
chriskrycho Jul 22, 2024
e669250
Ch. 17§00: phrasing/wording-level improvements
chriskrycho Jul 23, 2024
133bb61
Ch. 17§00: phrasing/wording-level improvements
chriskrycho Jul 23, 2024
4044534
Ch. 16: avoid slightly-dismissive language in transition
chriskrycho Jul 24, 2024
eb41efb
Ch. 17§00: rework the introduction based on initial reviews
chriskrycho Jul 24, 2024
cfaf187
Ch. 17: diagrams for concurrent and parallel execution
chriskrycho Jul 25, 2024
472f152
Ch. 17: fix diagrams and embed them in the text
chriskrycho Jul 26, 2024
fb718b3
Merge `main` into `async-edits`
chriskrycho Jul 31, 2024
ddad349
Merge `async-edits` into `only-new-async`
chriskrycho Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ jobs:
rustup --version
rustc -Vv
mdbook --version

# mdBook does not currently have particularly good support for “external”
# crates. To make the test suite work correctly with `trpl`, we must first
# build `trpl` itself (`mdbook` will not do it), and then explicitly pass
# its `deps` path as a library search path for `mdbook test`. That will make
# sure all the crates can be resolved when running the tests.
- name: Build `trpl` crate
run: |
cd packages/trpl
cargo build
- name: Run tests
run: mdbook test
run:
mdbook test --library-path packages/trpl/target/debug/deps
package_tests:
name: Run package tests
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions 2018-edition/src/ch17-03-oo-design-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-03-oo-design-patterns.html).
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
"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,
Expand Down
23 changes: 23 additions & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bool
boolean
Boolean
Booleans
booleans
Bors
BorrowMutError
BoxMeUp
Expand Down Expand Up @@ -109,6 +110,7 @@ deallocate
deallocated
deallocating
deallocation
debounce
debuginfo
decl
decrementing
Expand Down Expand Up @@ -145,6 +147,7 @@ DisplayBacktrace
DivAssign
DraftPost
DSTs
durations
ebook
ebooks
Edsger
Expand Down Expand Up @@ -179,6 +182,7 @@ filesystem's
filesystems
filmmaking
Firefox
FirstAwaitPoint
FnMut
FnOnce
formatter
Expand All @@ -197,6 +201,7 @@ grapheme
Grapheme
growable
gzip
handoff
hardcode
hardcoded
hardcoding
Expand Down Expand Up @@ -241,6 +246,7 @@ inline
instantiation
internet
interoperate
IntoFuture
IntoIterator
InvalidDigit
invariants
Expand All @@ -256,6 +262,7 @@ isize
iter
iterator's
JavaScript
JoinAll
JoinHandle
Kay's
kinded
Expand Down Expand Up @@ -294,6 +301,8 @@ Metadata
metaprogramming
mibbit
Mibbit
microcontroller
microcontrollers
millis
minigrep
mixup
Expand All @@ -307,17 +316,20 @@ monomorphized
MoveMessage
Mozilla
mpsc
MSRV
msvc
MulAssign
multibyte
multithreaded
multithreading
mutex
mutex's
Mutex
mutexes
Mutexes
MutexGuard
mutext
MyAsyncStateMachine
MyBox
myprogram
namespace
Expand Down Expand Up @@ -359,6 +371,7 @@ OutlinePrint
overloadable
overread
PanicPayload
parallelizable
param
parameterize
ParseIntError
Expand All @@ -371,6 +384,7 @@ PlaceholderType
polymorphism
PoolCreationError
portia
postfix
powershell
PowerShell
powi
Expand All @@ -396,6 +410,8 @@ RangeTo
RangeFull
README
READMEs
ReadFinished
ReceiverStream
rect
recurse
recv
Expand Down Expand Up @@ -438,6 +454,7 @@ sampleproject
screenshot
searchstring
SecondaryColor
SecondAwaitPoint
SelectBox
semver
SemVer
Expand All @@ -455,6 +472,7 @@ SliceIndex
Smalltalk
snuck
someproject
SomeType
someusername
SPDX
spdx
Expand All @@ -470,6 +488,7 @@ stdlib
stdout
steveklabnik's
stringify
StreamExt
Stroustrup
Stroustrup's
struct
Expand Down Expand Up @@ -514,6 +533,8 @@ tlborm
tlsv
TODO
TokenStream
Tokio
tokio
toml
TOML
toolchain
Expand All @@ -538,6 +559,7 @@ uncomment
Uncomment
uncommenting
unevaluated
unhandled
Uninstalling
uninstall
unittests
Expand All @@ -556,6 +578,7 @@ username
USERPROFILE
usize
UsState
util
utils
vals
variable's
Expand Down
44 changes: 44 additions & 0 deletions dot/trpl17-01.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
digraph {
dpi = 300.0;

rankdir = "LR";

// makes ordering between subgraphs work
newrank = true;

node [shape = diamond;];

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_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;
}
20 changes: 20 additions & 0 deletions dot/trpl17-02.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
digraph {
dpi = 300.0;

rankdir = "LR";
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;
}
}
7 changes: 7 additions & 0 deletions listings/ch17-async-await/listing-17-01/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions listings/ch17-async-await/listing-17-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions listings/ch17-async-await/listing-17-01/output.txt
Original file line number Diff line number Diff line change
@@ -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`
10 changes: 10 additions & 0 deletions listings/ch17-async-await/listing-17-01/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ANCHOR: all
fn main() {
hello("async");
}

async fn hello(name: &str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider including a -> () return type on this function so the comparison to impl Future<Output = ()> is clearer?

let greeting = format!("Hello, {name}!");
println!("{greeting}");
}
// ANCHOR_END: all
7 changes: 7 additions & 0 deletions listings/ch17-async-await/listing-17-02/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions listings/ch17-async-await/listing-17-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions listings/ch17-async-await/listing-17-02/output.txt
Original file line number Diff line number Diff line change
@@ -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:20
|
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
10 changes: 10 additions & 0 deletions listings/ch17-async-await/listing-17-02/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ANCHOR: main
fn main() {
hello("async").await;
}
// ANCHOR_END: main

async fn hello(name: &str) {
let greeting = format!("Hello, {name}!");
println!("{greeting}");
}
7 changes: 7 additions & 0 deletions listings/ch17-async-await/listing-17-03/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions listings/ch17-async-await/listing-17-03/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions listings/ch17-async-await/listing-17-03/output.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions listings/ch17-async-await/listing-17-03/src/main.rs
Original file line number Diff line number Diff line change
@@ -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}");
}
Loading