Commit Graph

69 Commits

Author SHA1 Message Date
Chris Krycho
38b2b8537f infra: dprint, part 2
- Reformat everything now that the bug in dprint for wrapping lines with
  inline code is fixed.
- Additionally, apply the formatting rules I *should have* applied the
  first time, so the repo has the same style it has historically used.
2024-12-05 14:05:53 -07:00
Chris Krycho
1882cfbb12 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.
2024-12-05 09:37:01 -07:00
Chris Krycho
9e2673a008 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).
2024-12-05 09:37:01 -07:00
Chris Krycho
3a30e4c1fb Apply dprint fmt to active files in the repo 2024-12-02 16:09:20 -07:00
Chris Krycho
7ee012f18b 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`.
2024-11-06 12:18:08 -07:00
Chris Krycho
c913659d62 infra: correctly report skipped paths in listings 2024-11-05 15:53:09 -07:00
dependabot[bot]
5b80fa3d18 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] <support@github.com>
2024-10-29 20:50:32 +00:00
Chris Krycho
55a2693f20 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.
2024-10-28 16:25:07 -06:00
Chris Krycho
be84fe8322 infra: change how packages are opted out of workspaces
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.
2024-10-25 15:26:31 -06:00
Chris Krycho
a328c6e639 infra: improve error handling for Listing
- Produce an error on unsupported `Listing` attributes. This will
  primarily prevent us from ending up with typos.
- Improve the error handling for missing attributes, and add tests to
  guarantee we do what we expect.
2024-10-15 08:37:55 -06:00
Chris Krycho
75ec154789 infra: publish trpl@0.2.0 w/new features from edits 2024-09-25 15:22:57 -06:00
Chris Krycho
cc5db97693 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!
2024-09-20 16:46:37 -06:00
Chris Krycho
487c81df35 Merge main into async-edits (Rust 1.81 update) 2024-09-12 11:40:54 -06:00
Chris Krycho
c552952e9f 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.
2024-09-12 11:40:54 -06:00
Chris Krycho
6b6b4501f1 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.
2024-09-11 07:26:31 -06:00
Chris Krycho
fb718b3822 Merge main into async-edits 2024-08-19 07:22:33 -06:00
Carol (Nichols || Goulding)
b988be3cb9 Instead of special casing square brackets in code, don't support md links without something after them 2024-08-13 21:19:47 -04:00
Eric Huss
d179c23616 mdbook-trpl-listing: Add missing elided lifetimes 2024-07-29 11:32:29 -07:00
Chris Krycho
79fd5e2dd1 Merge main into async-edits 2024-07-22 12:06:26 -06:00
Chris Krycho
d10039ff03 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!
2024-07-17 15:58:42 -06:00
Chris Krycho
dc8d7e870c Merge main into async-edits 2024-07-17 13:29:42 -06:00
Chris Krycho
22b04c1385 infra: prepare trpl crate for 0.1.0 release 2024-07-16 09:00:23 -06:00
Chris Krycho
7bd97c9688 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.
2024-07-15 17:07:20 -06:00
Chris Krycho
4d357442af 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.
2024-07-15 17:07:20 -06:00
Chris Krycho
28230e6cb4 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.
2024-07-15 09:24:14 -06:00
Chris Krycho
92c19ce9cf Ch. 17§06 initial edits 2024-07-12 15:40:22 -06:00
Chris Krycho
1a90722c93 Merge main into async-edits 2024-07-12 15:23:24 -06:00
Chris Krycho
ef1ed96053 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.
2024-07-09 09:22:58 -06:00
Carol (Nichols || Goulding)
1f7ac86353 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.
2024-07-05 20:32:23 -04:00
Chris Krycho
f023032403 Ch. 17: add some more explanatory comments to trpl 2024-07-02 09:12:03 -06:00
Chris Krycho
b4f5763368 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!
2024-06-25 14:57:45 -06:00
Chris Krycho
e790c2cc90 Ch. 17: re-export Stream, StreamExt, and stream_iter in trpl 2024-06-20 13:45:50 -06:00
Chris Krycho
67bd0a08bc 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!
2024-06-13 13:38:38 -06:00
Chris Krycho
c310f54aab Ch. 17: Finish (first pass) documentation for trpl::race
Explain how it relates to `futures::future::select` and why `trpl` uses
`race` semantics instead.
2024-06-13 08:14:22 -06:00
Chris Krycho
2360484f63 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.)
2024-06-12 15:28:01 -06:00
Chris Krycho
71acd6d091 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`.
2024-06-12 13:42:09 -06:00
Chris Krycho
7da440af2e 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.
2024-06-12 13:42:09 -06:00
Chris Krycho
c58f94376c Ch. 17 §02: Start on example of select. 2024-06-12 13:42:09 -06:00
Chris Krycho
c6965ca057 Ch. 17 §02: Start showing timeouts
This also has the setup for showing `select`, but currently jumps ahead
to showing a `timeout` example.
2024-06-12 13:42:09 -06:00
Chris Krycho
068f30b406 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.
2024-06-12 13:42:09 -06:00
Chris Krycho
d3d7c64db8 Merge main into only-new-async 2024-06-12 13:42:09 -06:00
Chris Krycho
b3fe5b776b Merge main into only-new-async 2024-06-12 13:42:09 -06:00
Chris Krycho
b835c0726a Merge main into only-new-async 2024-06-12 13:42:09 -06:00
Chris Krycho
4b7886e092 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.
2024-06-12 13:42:09 -06:00
Chris Krycho
c1c3c7fac8 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.
2024-06-12 13:42:09 -06:00
Chris Krycho
dacddb58b4 Merge main into only-new-async 2024-06-12 13:42:09 -06:00
Chris Krycho
f418ceba2e 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.
2024-06-12 13:42:09 -06:00
Chris Krycho
95105d23d7 Ch. 17: Add futures to trpl crate for re-exports 2024-06-12 13:42:09 -06:00
Chris Krycho
96fd725596 Merge main into only-new-async 2024-06-12 13:42:09 -06:00
Chris Krycho
dbd5e149b8 Ch. 17: use Listing for all existing listings 2024-06-12 13:42:09 -06:00