mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-07-06 11:07:12 -06:00
finshed ch17.1
This commit is contained in:
2127
hello-async/Cargo.lock
generated
Normal file
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
7
hello-async/Cargo.toml
Normal 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
21
hello-async/src/main.rs
Normal 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())
|
||||
}
|
Reference in New Issue
Block a user