Skip to content

Commit

Permalink
Update to main and add async chapter (#206)
Browse files Browse the repository at this point in the history
* Convert chapters 12-15

* Remove extraneous span

* Ch. 17: reorganize 17.01 and get a useable intro to Future

* Ch. 17: wording and formatting in 17.01

* Ch. 17: corrections/discussion on runtimes, mostly

- 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.

* Ch. 17: pull disconnected material out of 17.01

* Ch. 17: minor wording improvement

* Ch. 17: eliminate duplicate runtime description

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”.

* Ch. 17: Add `futures` to `trpl` crate for re-exports

* 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.

* Ch. 17: start in earnest on §2, showing relation to threads

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!

* Ch. 17: add more examples and explanation to §02.

* 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.

* Ch. 17: start on message-passing and `async move` in §2

- Introduce the relevant supporting features in `trpl`.
- Add a couple listings to show how things do or do not work.

* 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.

* Exclude `trpl` from workspace

It should manage its own dependencies.

* 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!

* Ch. 17: inline some note content and fix some phrasing

* Ch. 17: Rewrite listings to be more similar to Ch. 16

* Ch. 17: wording and structure tweaks

* Ch. 17: show multiple producers working with `clone`

* Ch. 17: restructure §00 and start better motivating async

* 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.

* Ch. 17: rework §00 to talk about reads instead of writes

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.

* Ch. 17: extract parallelism discussion from §00 to §03

§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?

* Ch. 17: dedicate §03 to 'Futures, Tasks, and Threads'

- Move the heading out from §03.
- Add this to the summary.

* Ch. 17: Listings are all `17-*`!

* Ch. 17: Fill out message-passing example

- 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.

* Ch. 17: A minor wording improvement

* 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 =
<same>` 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.

* 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.

* Ch. 17: A small wording tweak about `JoinAll` in §03

* Ch. 17: Start building out explanation of `Pin`

* 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

* Ch. 17: iterate on §02 examples, extract “extra” material

* Ch. 17: Explain `join!` in §02

* Ch. 17 §02: Clarify the `move` discussion

* Ch. 17 §02: Start showing timeouts

This also has the setup for showing `select`, but currently jumps ahead
to showing a `timeout` example.

* Ch. 17 §02: Start on example of select.

* Ch. 17 §02: Implement `timeout` example and building blocks

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.

* Ch. 17: build a `retry` implementation

This is good to know about, but has significant problems, mostly down to
the issues Niko covers in [this post][post] regarding the way ownership
and closures interact. See [this Stack Overflow answer][so], which
applies that dynamic specifically to a `retry` implementation which
happens to be more or less identical to what I built here!

[post]: https://smallcultfollowing.com/babysteps/blog/2023/05/09/giving-lending-and-async-closures/
[answer]: https://stackoverflow.com/questions/75533630/how-to-write-a-retry-function-in-rust-that-involves-async

* Ch. 17: Drop material about `retry`, since it is a hazard

As described in the parent commit, what I have here technically works
but is adjacent to an area of the language which does *not* yet work as
well as we might hope: closures which involve async. Since even the
smallest refactor here (extracting the future *or* the closure to a
standalone binding) breaks the code, best to remove it entirely in favor
of some other example of composing futures together.

backout of commit d5ed8de

* Ch. 17 §02: Write about `race` and `yield_now`

- Update the implementation for `race` to use `futures::future::Either`
  instead of duplicating the type, and update the test not to try to use
  equality.
- Add a `pub use` for `tokio::task::yield_now`.

* Ch. 17: Split the over-long §02 into two parts

…and fix a bunch of the listing references and make some word choice and
sentence structure improvements along the way to boot.

* Ch. 17: Show worked example of implementing `timeout`

* Ch. 17 §04: Show perforance of `sleep` vs. `yield_now`

* Ch. 17 §01: rephrase note about the details we don’t get into

* Ch. 17 §01: Add necessary background for §04 to make sense

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.

* Ch. 17 §04: Explain the *implications* of yielding to motivate it

* Ch. 17 §04: explain yield better and rework examples

- Actually show “slow” work with interleaved await points in examples.
- Explain in detail how the slow work and the await points interact.

* Ch. 17 §04: Add a good transition sentence

* Ch. 17 §04: add a Note about cooperative multitasking

* Ch. 17 §03: Add more explanatory material on `Pin`

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.

* Ch. 17: a better name for one of the internal sections

* Ch. 17 §03: Explain pinning and `Deref` just enough

* Ch. 17 §03: Finish a first pass on explaining `Pin`

* Ch. 17 §04: Code sample and incomplete sentence fixes

* Ch. 17 §04: Give the section a reasonable title

* Ch. 17: an editing pass on §00 and the start of §01

* 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.)

* Ch. 17: correct listing numbers for §01

* Ch. 17 §01: flag a TODO item for later

* Ch. 17: Finish (first pass) documentation for `trpl::race`

Explain how it relates to `futures::future::select` and why `trpl` uses
`race` semantics instead.

* Fix a typo in `ADMIN_TASKS`

* Ch. 17 §02: correct numbering and content for Listing 17-04

* Ch. 17 §02: correct numbering and content for Listing 17-05

* Ch. 17 §02: correct numbering and content for Listing 17-06

* Ch. 17 §02: remove listing that I split into multiple parts

* Ch. 17 §02: correct numbering and content for Listing 17-07

* Ch. 17 §02: leave a TODO about one bucket of output

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?

* Ch. 17 §02: correct numbering and content for Listings 17-08 and 17-09

* Ch. 17 §02: correct numbering and content for Listings 17-10 and 17-11

* Ch. 17 §02: correct numbering and content for Listing 17-12

* Ch. 17 §02: correct numbering and content for Listings 17-13 and 17-14

* Ch. 17 §02: correct numbering and content for Listings 17-15 and 17-16

* Ch. 17 §03: correct numbering and content for Listings 17-17

* Ch. 17 §03: correct numbering and content for Listing 17-18

* Ch. 17: Fix internal links

- Align them with the existing format for links.
- Add one missing link.

* Ch. 17: Remove completed `TODO` for `Pin` 🎉

* Ch. 17 §03: extract a no-listing for type mismatches

* Ch. 17 §03: correct numbering and content for Listings 17-19 and 17-20

* Ch. 17 §03: support code for motivating `Pin`

- 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!

* Ch. 17 §03: add a TODO for checking Pin description correctness

* Ch. 17 §03: correct listings and wording for `Pin` materials

* Revert chapter 15

* Ch. 17 §03: correct listings and wording for first half of section

* Ch. 17: renumber listings to eliminate `no-listing` listings

* Ch. 17: finish listing numbers for §04

* Ch. 17 §01: make the conclusion section coherent

* Ch. 17 §02: transition for §03 and TODO cleanup

* Ch. 17: Add a new §05 on Stream and AsyncIterator

This pushes back the Tasks, Futures, and Threads discussion one more
spot, to become §06.

* Ch. 17 S§02: introduce and explain `while let` syntax.

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`.

* Ch. 17 §05: Introduce `Stream` and drop `AsyncIterator`

* Ch 17. §01: leave a TODO about `IntoFuture`

* Ch. 17 §05: start explaining how we work with streams

* infra: ignore Nova configuration directory

* Ch. 17: Remove a now-properly-numbered listing

I moved this into dedicated listings appropriately but forgot to remove
the original.

* Ch. 17 (infra): add a base listing to use when generating new ones

* Ch. 17: re-export `Stream`, `StreamExt`, and `stream_iter` in `trpl`

* Ch. 17 §05: describe how to use `Stream`s with `Iterator`s

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.

* Update ch10-00-generics.md

* Ch. 17: final example for §05, with more re-exported streams

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!

* Ch. 17 §05: First part of final example, with `ReceiverStream`

* Ch. 17 §05: complete example with `throttle` and `take`

* Ch. 17 §06: Start discussing future/task/thread tradeoffs

- Reintroduce accidentally-dropped content. I meant to simply carry this
  over in 74df84e, 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.

* Ch. 17 §06: more on tasks and threads, better example

* Ch. 17: Most of §06 drafted, needs a conclusion

- 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.

* Ch. 17 §00: rewrite the parallelism and concurrency section

* Ch. 17 §00: no more cooks!

* Ch. 17: remove 'base' listing

* 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.

* Ch. 17§00 initial edits

* Ch. 17: add some more explanatory comments to `trpl`

* Ch. 17§01 initial edits for the first subsection

* Ch. 17§01 initial edits for the second subsection

* Ch. 17§02 initial edits on 'Counting'

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!).

* Ch. 17§02 initial edits on 'Message Passing'

- 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.

* Ch. 17§03 Initial edits on opening section

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.!

* Upgrade to Rust 1.79.0

* Backport changes to chapter 11

* Don't just discard output without examining it when doing manual update here

* Remove anchors around entire listings

* Increase consistency with what cargo new --lib generates

* 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.

* Snapshot changes to generated ch11 that SHOULDN'T be sent to nostarch

* Snapshot changes to ch11 to consider sending to nostarch

* Yes, RUSTFLAGS is a word

* Ch. 17§03 initial edits on pinning section

- 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.

* Ch. 17§03: Rename the section for clarity

* Ch. 17: remove now unused Listing 17-24

* Ch. 17§04 initial edits on intro and “Yielding” section

* Ch. 17§04 initial edits on Building Our Own Async Abstractions

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.

* Use Rust 2021 Edition for mdBook

A number of examples *already* do not work correctly, and the inbound
async chapter requires Rust 2021.

* Ch. 17§05 initial edits on first two sections

- 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.

* Ch. 17§05 initial edits on 'Composing Streams'

* Ch. 17§05 initial edits on 'Merging Streams'

* Ch. 17§06 initial edits

* 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.

* infra: support non-numbered and no-caption listings

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.

* 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.

* Ch. 17 §03: restore accidentally-removed Listing 17-14

* infra: prepare `trpl` crate for 0.1.0 release

* Ch. 17§03: fix typo

htypes! What are htypes? No one will ever know.

Co-authored-by: James Munns <[email protected]>

* Ch. 17: correct wrapping for a `Note`

* Ch. 17: Update CI config to support testing the book with `trpl`

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.


.github/workflows/main.yml

* Ch. 17§01: Make code/listings pass tests

- Update the contents of the code in the chapter so it is correct, and
  update the text to match. Given this is about `Future`, this may also
  warrant moving/simplifying that whole chunk of code, too.

- Update the listing to use `extern crate` since it does not otherwise
  work correctly with `mdbook test`. Alas.

* Ch. 17§02: Make code/listings pass tests

- Update all the listings in the chapter to use `extern crate` since
  `mdbook test` does not understand Rust 2018. Alas.
- Ignore two of the listings because they never stop.

* Ch. 17§03: Make code/listings pass tests

- 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!)

* Ch. 17§04: Make code/listings pass tests

- 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.

* Ch. 17§05: Make code/listings pass tests

- 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.

* Ch. 17§06: Make code listing pass tests and add a caption

* 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!

* Ch. 17: fix spelling issues

* 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.

* Ch. 17: fix an internal link reference

* infra: fix some shellcheck issues in CI config

* Clarify function definitions vs. expressions

Fixes rust-lang#2980.

* Ch. 17§00: phrasing/wording-level improvements

Co-authored-by: Tim McNamara <[email protected]>
Co-authored-by: James Munns <[email protected]>

* Ch. 17§00: phrasing/wording-level improvements

Co-authored-by: Carol (Nichols || Goulding) <[email protected]>
Co-authored-by: Will Crichton <[email protected]>
Co-authored-by: Tim McNamara <[email protected]>

* 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 <[email protected]>) for pointing
out how my rephrasing here made it worse!

* Ch. 17§00: rework the introduction based on initial reviews

- 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.

* Ch. 17: diagrams for concurrent and parallel execution

* 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.

* mdbook-trpl-listing: Add missing elided lifetimes

* 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!

* infra: include ghp-import and git push in generate-preview script

* Fix: typo

Fix a typo in ch03-05-control-flow.md

* Remove redundant sentence. Send to nostarch

Fixes rust-lang#3994.

* Fix unfancy quotes

* Updates to ch7 snapshot, not to send to nostarch

* Upstream changes to ch7 to consider sending to nostarch

* Backported edits of ch12 from print to src

* Reword to avoid a/an where pronunciation is unclear

* Make all search word arguments italics

* Instead of special casing square brackets in code, don't support md links without something after them

* Snapshot changes to generated ch12 that SHOULDN'T be sent to nostarch

* Snapshot changes to ch 12 to consider sending to nostarch

* Ch. 17: Fix up diagrams

- 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.

* Ch. 17§00: second round of edits

* Use immutable borrow of `TcpStream` when creating `BufReader`

* WIP quizzes

* More quizzes

* cargo init usage suggestion

* Ch. 17: start restructuring chapter

- 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.

* 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.

* Clarify Cargo.toml generation with `cargo init`.

* Update build instructions: include mdbook plugins

Fixes rust-lang#4018

* 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.

* 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.

* Upgrade Ch. 17 listings for Rust 1.81

* Ch. 17: rework 17.03 (and overall structure) from my own analysis

* 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.

* Ch. 17: rework 17.05 with my own edits and analysis

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.

* Ch. 17: fold together 17.03 and 17.04

* Ch. 17: Make the new 17.05 actually work as a deep dive!

* Ch. 17: integrate a number of the outstanding review comments

Bonus: fix some style guide issues, too!

Co-authored-by: Carol (Nichols || Goulding) <[email protected]>
Co-authored-by: James Munns <[email protected]>
Co-authored-by: Tim McNamara <[email protected]>

* Ch. 17: address the rest of James’ review comments 🎉

Co-authored-by: James Munns <[email protected]>

* Ch. 17: address most of the rest of Carol's outstanding comments

* Ch. 17: address Tim and Carol's outstanding comments

Co-authored-by: Tim McNamara <[email protected]>
Co-authored-by: Carol (Nichols || Goulding) <[email protected]>

* Ch. 17: Fix some typos!

* 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!

* Ch. 17: rewrite 17.01 with a better example

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!

* 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.

* Ch. 17: Fix spelling and internal links

* Update quizzes

---------

Co-authored-by: bryanzierk <[email protected]>
Co-authored-by: Chris Krycho <[email protected]>
Co-authored-by: Yung Beef 4.2 <[email protected]>
Co-authored-by: Carol (Nichols || Goulding) <[email protected]>
Co-authored-by: James Munns <[email protected]>
Co-authored-by: Tim McNamara <[email protected]>
Co-authored-by: Eric Huss <[email protected]>
Co-authored-by: Vox Dai <[email protected]>
Co-authored-by: Bin Wang <[email protected]>
Co-authored-by: faint <[email protected]>
  • Loading branch information
11 people authored Sep 26, 2024
1 parent e6cc62f commit 7341735
Show file tree
Hide file tree
Showing 268 changed files with 33,947 additions and 1,216 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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 Depot
run: curl https://raw.githubusercontent.com/cognitive-engineering-lab/depot/main/scripts/install.sh | sh
Expand Down Expand Up @@ -112,9 +112,20 @@ jobs:
# https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
# # Cannot use --all here because of the generated redirect pages aren't available.
# sh linkcheck.sh book


# 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 mdbook tests
run: mdbook test
run:
mdbook test --library-path packages/trpl/target/debug/deps

- name: Build mdbook
run: mdbook build
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).
10 changes: 10 additions & 0 deletions ADMIN_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 18 additions & 18 deletions Cargo.lock

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

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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ You should install the same version of each preprocessor [used in CI](https://gi

Finally, you need [pnpm](https://pnpm.io/installation).

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

### With cargo-make
Expand Down Expand Up @@ -94,7 +104,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
Expand Down
6 changes: 5 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ additional-css = [
"ferris.css",
"theme/semantic-notes.css",
"theme/listing.css",
"theme/2018-edition.css",
"js-extensions/packages/consent-form/dist/index.css",
"js-extensions/packages/feedback/dist/index.css",
]
Expand Down Expand Up @@ -39,4 +40,7 @@ more-words = "words.dic"
[preprocessor.trpl-listing]
output-mode = "default"

# [output.linkcheck]
# [output.linkcheck]

[rust]
edition = "2021"
30 changes: 30 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,10 +147,12 @@ DisplayBacktrace
DivAssign
DraftPost
DSTs
durations
ebook
ebooks
Edsger
egular
ElementRef
else's
emoji
encodings
Expand Down Expand Up @@ -179,6 +183,7 @@ filesystem's
filesystems
filmmaking
Firefox
FirstAwaitPoint
FnMut
FnOnce
formatter
Expand All @@ -187,6 +192,8 @@ FrenchToast
FromIterator
FromResidual
frontend
FuturesUnordered
GetAwaitPoint
getrandom
getter
getters
Expand All @@ -197,6 +204,7 @@ grapheme
Grapheme
growable
gzip
handoff
hardcode
hardcoded
hardcoding
Expand Down Expand Up @@ -241,7 +249,9 @@ inline
instantiation
internet
interoperate
IntoFuture
IntoIterator
intra
InvalidDigit
invariants
ioerror
Expand All @@ -256,6 +266,7 @@ isize
iter
iterator's
JavaScript
JoinAll
JoinHandle
Kay's
kinded
Expand Down Expand Up @@ -288,12 +299,15 @@ lval
macOS
Matsakis
mathematic
mdbook
memoization
metadata
Metadata
metaprogramming
mibbit
Mibbit
microcontroller
microcontrollers
millis
minigrep
mixup
Expand All @@ -307,17 +321,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 @@ -358,7 +375,9 @@ OurError
OutlinePrint
overloadable
overread
PageTitleFuture
PanicPayload
parallelizable
param
parameterize
ParseIntError
Expand All @@ -371,6 +390,7 @@ PlaceholderType
polymorphism
PoolCreationError
portia
postfix
powershell
PowerShell
powi
Expand All @@ -396,6 +416,8 @@ RangeTo
RangeFull
README
READMEs
ReadFinished
ReceiverStream
rect
recurse
recv
Expand Down Expand Up @@ -438,6 +460,7 @@ sampleproject
screenshot
searchstring
SecondaryColor
SecondAwaitPoint
SelectBox
semver
SemVer
Expand All @@ -455,6 +478,7 @@ SliceIndex
Smalltalk
snuck
someproject
SomeType
someusername
SPDX
spdx
Expand All @@ -470,6 +494,7 @@ stdlib
stdout
steveklabnik's
stringify
StreamExt
Stroustrup
Stroustrup's
struct
Expand Down Expand Up @@ -502,6 +527,7 @@ TcpListener
TcpStream
templating
test's
TextAwaitPoint
TextField
That'd
there'd
Expand All @@ -514,6 +540,8 @@ tlborm
tlsv
TODO
TokenStream
Tokio
tokio
toml
TOML
toolchain
Expand All @@ -538,6 +566,7 @@ uncomment
Uncomment
uncommenting
unevaluated
unhandled
Uninstalling
uninstall
unittests
Expand All @@ -556,6 +585,7 @@ username
USERPROFILE
usize
UsState
util
utils
vals
variable's
Expand Down
Loading

0 comments on commit 7341735

Please sign in to comment.