我无法从Result
. 每个教程只展示如何使用一个结果,而不是如何从它返回一个值。
fn main(){
let mut a: Vec<String> = Vec::new();
a = gottem();
println!("{}", a.len().to_string());
//a.push(x.to_string()
}
async fn gottem() -> Result<Vec<String>, reqwest::Error> {
let mut a: Vec<String> = Vec::new();
let res = reqwest::get("https://www.rust-lang.org/en-US/")
.await?
.text()
.await?;
Document::from(res.as_str())
.find(Name("a"))
.filter_map(|n| n.attr("href"))
.for_each(|x| println!("{}", x));
Ok(a)
}
我收到以下错误:
error[E0308]: mismatched types
--> src/main.rs:13:9
|
13 | a = gottem();
| ^^^^^^^^ expected struct `std::vec::Vec`, found opaque type
...
18 | async fn gottem() -> Result<Vec<String>, reqwest::Error> {
| ----------------------------------- the `Output` of this `async fn`'s found opaque type
|
= note: expected struct `std::vec::Vec<std::string::String>`
found opaque type `impl std::future::Future`