1

我想将 Select.rs 的Find-iterator 转换为 Rayon ParallelIterator。我无法通过简单地使用 API 来做到这一点。我怀疑我必须实现或扩展一个特征,但我不知道该怎么做。

我试过收集 Iterator 和 using into_iter,但无济于事。

use reqwest;

use rayon::prelude::*;

use select::document::Document;
use select::predicate::{Class};

fn main() {
    println!("Hello, world!");

    let url = "https://pitchfork.com/reviews/albums/";
    let response = reqwest::get(url).unwrap();
    if response.status().is_success() {
        let document = Document::from_read(response).unwrap();
        let albums = document.find(Class("review"));
        let albums : Vec<String> = albums.par_iter()
                                        .map(|album| album.text()).collect();
    }
}

这会导致错误

error[E0599]: no method named `par_iter` found for type `select::document::Find<'_, select::predicate::Class<&str>>` in the current scope
  --> src/main.rs:16:40
   |
16 |         let albums : Vec<String> = albums.par_iter()
   |                                           ^^^^^^^^
   |
   = note: the method `par_iter` exists but the following trait bounds were not satisfied:
           `select::document::Find<'_, select::predicate::Class<&str>> : rayon::iter::IntoParallelRefIterator`

我看到该方法par_iter不存在,但该方法似乎也不存在iter

我认为有一种方法可以实现这一点,而无需创建对 select.rs 的拉取请求 - 无论哪种方式,我们都将不胜感激。

4

0 回答 0