Commit Graph

348 Commits

Author SHA1 Message Date
Dane Harrigan
d65bd3cc31 Revise annotations to not refer to subjects as it 2024-12-05 10:44:47 -05:00
Chris Krycho
fb46a07bf3 Merge pull request #3809 from octavioooooo/patch-1
Rephrase for clarity
2024-11-27 09:15:05 -07:00
Chris Krycho
52b9e2a040 Match NoStarch style guide for updated Listing 4-3 comment 2024-11-27 09:11:30 -07:00
Chris Krycho
93d741a77b 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.
2024-11-22 14:52:18 -07:00
Chris Krycho
da611679cd Correct baseline after running update-rustc.sh again 2024-11-06 13:45:39 -07:00
Chris Krycho
af61f9529c Fix output paths for updates in Ch. 20 2024-11-06 12:57:59 -07:00
Chris Krycho
3fdb520364 Introduce basic usage of Miri in the unsafe chapter 2024-11-06 12:36:43 -07:00
Chris Krycho
48d0b7686b 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.
2024-11-06 12:36:43 -07:00
Chris Krycho
2b1ddf4911 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.
2024-11-06 12:36:43 -07:00
Chris Krycho
f04d20fe8d Rust 1.82: also update all cases of manual regeneration 2024-11-06 11:49:14 -07:00
Chris Krycho
96501370c2 Update to Rust 1.82 2024-11-05 15:53:09 -07:00
Chris Krycho
e28cd5b13f Set the correct baseline for current Rust version
Unfortunately missed some of this when updating to Rust 1.81
2024-11-04 13:15:19 -07:00
Chris Krycho
a92d8e6c2d Update Cargo.lock for all Ch. 17 listings 2024-11-04 12:48:51 -07:00
Jason O'Donnell
b1f6e062b4 add semicolon to 19-16 2024-10-24 09:26:15 -04:00
Jason O'Donnell
1c6c44568e add missing semicolon in listing 19-15 2024-10-24 09:17:05 -04:00
Chris Krycho
62d441060d 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`.
2024-10-17 07:41:42 -06:00
Chris Krycho
54c567b5b2 Ch. 17: update all internal links for new ordering 2024-10-08 10:16:44 -06:00
Chris Krycho
c8f446419a Ch. 17: Listings for old Ch. 17 -> Ch. 18 2024-10-08 10:16:44 -06:00
Chris Krycho
1f6ce67841 Ch. 17: Listings for Ch. 18 -> Ch. 19 2024-10-08 10:16:44 -06:00
Chris Krycho
82f91e7830 Ch. 17: Listings for Ch. 19 -> Ch. 20 2024-10-08 10:16:44 -06:00
Chris Krycho
fb0215d910 Ch. 17: Listings for Ch. 20 -> Ch. 21 2024-10-08 10:16:44 -06:00
Chris Krycho
887694bfde Ch. 17: update all the listing lock files 2024-10-08 10:16:20 -06:00
Chris Krycho
8aee93d82d Ch. 17: include main when first showing trpl::run
This gives people a better chance of understanding how the pieces fit
together.
2024-10-07 14:16:31 -06:00
Chris Krycho
06a3a7194a Merge main into async-chapter 2024-10-07 12:47:53 -06:00
Herbert Reiter
2017a78b41 Swap assert_eq! parameters 2024-10-06 14:55:47 +02:00
Carol (Nichols || Goulding)
48379d38aa Update code and output to match text 2024-10-01 17:21:41 -04:00
Chris Krycho
dc67ffe78f 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.
2024-10-01 09:36:32 -06:00
Chris Krycho
0388426c51 Ch. 17: Fix no-listing code for state machine enum 2024-09-25 15:22:57 -06:00
Chris Krycho
42b59635d2 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.
2024-09-25 08:49:28 -06:00
Chris Krycho
573a6ca4ba 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.
2024-09-23 08:55:11 -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
c35b7d9453 Ch. 17: address most of the rest of Carol's outstanding comments 2024-09-13 14:15:37 -06:00
Chris Krycho
6bdf1b71f3 Merge main into async-edits 2024-09-12 12:20:35 -06:00
Chris Krycho
7da825f835 Ch. 17: Make the new 17.05 actually work as a deep dive! 2024-09-12 12:20:35 -06:00
Chris Krycho
3cfdf2d66a Ch. 17: rework 17.03 (and overall structure) from my own analysis 2024-09-12 11:40:54 -06:00
Chris Krycho
9b13b95ca1 Upgrade Ch. 17 listings for Rust 1.81 2024-09-12 11:40:54 -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
28a24440b1 Merge pull request #4024 from bin-wang/remove-mut
Use immutable borrow of `TcpStream` when creating `BufReader`
2024-09-11 16:54:33 -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
Bin Wang
c648c0e8da Use immutable borrow of TcpStream when creating BufReader 2024-08-30 16:40:55 -04:00
Chris Krycho
5099e5fb55 Ch. 17§06: Make code listing pass tests and add a caption 2024-07-17 15:43:53 -06:00
Chris Krycho
40bdda77f8 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.
2024-07-17 15:43:53 -06:00
Chris Krycho
0aacb80bf2 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.
2024-07-17 15:21:25 -06:00
Chris Krycho
6a0d07280a 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!)
2024-07-17 15:14:54 -06:00
Chris Krycho
deefe4d518 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.
2024-07-17 14:56:25 -06:00
Chris Krycho
24ed6e4c11 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.
2024-07-17 14:54:36 -06:00
Chris Krycho
c3c88e4b4f Ch. 17 §03: restore accidentally-removed Listing 17-14 2024-07-15 17:30:49 -06:00
Chris Krycho
92c19ce9cf Ch. 17§06 initial edits 2024-07-12 15:40:22 -06:00
Chris Krycho
2797d950ab Ch. 17§05 initial edits on 'Merging Streams' 2024-07-12 15:23:24 -06:00