finshed ch17.1
Some checks failed
Test Gitea Actions / first (push) Successful in 16s
Test Gitea Actions / check-code (push) Failing after 15s
Test Gitea Actions / test (push) Has been skipped
Test Gitea Actions / documentation-check (push) Has been skipped

This commit is contained in:
2025-03-19 16:16:19 -06:00
parent 20d58f8ef5
commit 8f01c0e0e4
8 changed files with 2597 additions and 19 deletions

2127
hello-async/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
hello-async/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "hello-async"
version = "0.1.0"
edition = "2024"
[dependencies]
trpl = "0.2.0"

21
hello-async/src/main.rs Normal file
View File

@ -0,0 +1,21 @@
extern crate trpl;
use trpl::Html;
async fn main() {
let args: Vec<String> = std::env::args().collect();
let url = &args[1];
match page_title(url).await {
Some(title) => println!("The title for {url} was {title}"),
None => println!("{url} had no title"),
}
}
async fn page_title(url: &str) -> Option<String> {
let res = trpl::get(url).await;
let res_text = res.text().await;
Html::parse(&res_text)
.select_first("title")
.map(|title_element| title_element.inner_html())
}