小编Dud*_*de4的帖子

无法调用返回结果的函数:找到不透明类型 impl std::future::Future

我无法从 a 返回函数的结果Result。每个教程只展示如何使用 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)
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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 …
Run Code Online (Sandbox Code Playgroud)

rust reqwest rust-result

3
推荐指数
1
解决办法
4183
查看次数

标签 统计

reqwest ×1

rust ×1

rust-result ×1