0

我正在尝试将Roliz 的网络爬虫博客文章)转换为 WASM,以进行浏览器内或基于 Deno 的端点爬取。

这是我的实现:

货运.toml

[dependencies]
wasm-bindgen = "0.2.67"
wasm-bindgen-futures = "0.4.17"
rayon = "1.3.1"

库文件

#![feature(async_closure)]

use rayon::prelude::*;
use std::collections::HashSet;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

fn get_links_from_html(html: &str, origin: &str) -> HashSet<String> {
    Default::default()
}

async fn fetch_url(url: &str) -> Result<String> {
    Ok(Default::default())
}

pub async fn crawl(input: &str) {
    let mut new_urls: HashSet<String> = Default::default();

    let (found_urls, errors): (Vec<Result<HashSet<String>>>, Vec<_>) = new_urls
        .par_iter()
        .map(async move |url| -> Result<HashSet<String>> {
            let body = fetch_url(url).await.unwrap();
            let links = get_links_from_html(&body, input);
            Ok(links)
        })
        .partition(Result::is_ok); //This is where the error is occurring
}

操场。完整的错误信息是:

error[E0631]: type mismatch in function arguments
   --> src/main.rs:110:24
    |
110 |             .partition(Result::is_ok);
    |                        ^^^^^^^^^^^^^
    |                        |
    |                        expected signature of `for<'r> fn(&'r impl std::future::Future) -> _`
    |                        found signature of `for<'r> fn(&'r std::result::Result<_, Error>) -> _`

error[E0277]: the trait bound `std::vec::Vec<std::result::Result<std::collections::HashSet<std::string::String>, Error>>: rayon::iter::ParallelExtend<impl std::future::Future>` is not satisfied
   --> src/main.rs:110:14
    |
110 |             .partition(Result::is_ok);
    |              ^^^^^^^^^ the trait `rayon::iter::ParallelExtend<impl std::future::Future>` is not implemented for `std::vec::Vec<std::result::Result<std::collections::HashSet<std::string::String>, Error>>`
    |
    = help: the following implementations were found:
              <std::vec::Vec<T> as rayon::iter::ParallelExtend<&'a T>>
              <std::vec::Vec<T> as rayon::iter::ParallelExtend<T>>

我正在使用 rust 版本:1.45.0-nightly (4bd32c980 2020-05-29)


我哪里错了?

4

0 回答 0