Skip to content

Commit

Permalink
[WIP] Ch. 17: rewrite the opening example
Browse files Browse the repository at this point in the history
- Add `reqwest` and `scraper` dependencies to the `trpl` crate.
  • Loading branch information
chriskrycho committed Sep 16, 2024
1 parent 6f5773e commit d141a02
Show file tree
Hide file tree
Showing 25 changed files with 10,927 additions and 286 deletions.
1,890 changes: 1,742 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 0 additions & 2 deletions listings/ch17-async-await/listing-17-10/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ fn main() {
};

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;
Expand Down
1 change: 0 additions & 1 deletion listings/ch17-async-await/listing-17-11/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ fn main() {
// ANCHOR_END: with-move
});
}
// ANCHOR_END: all
7 changes: 7 additions & 0 deletions listings/ch17-async-await/listing-scraper-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "listing-scraper-01"
version = "0.1.0"
edition = "2021"

[dependencies]
trpl = { path = "../../../packages/trpl" }
17 changes: 17 additions & 0 deletions listings/ch17-async-await/listing-scraper-01/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extern crate trpl; // required for mdbook test

fn main() {
// TODO: we'll add this next!
}

// ANCHOR: all
use trpl::Html;

async fn page_title_for(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| title.inner_html())
}
// ANCHOR_END: all
Loading

0 comments on commit d141a02

Please sign in to comment.