1

I would like to convert Select.rs's Find-iterator into a Rayon ParallelIterator. I haven't been able to do this by simply mucking about with the API. I suspect I shall have to implement or extend a trait, but I have no clue how to do it.

I've tried collecting the Iterator and using into_iter, but to no avail.

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();
    }
}

This results in the error

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`

I see that the method par_iter doesn't exist, but it doesn't appear that the method iter does either.

I assume there is a way of accomplishing this without having to create a pull request to select.rs - either way, assistance would be appreciated.

hellow
  • 12,430
  • 7
  • 56
  • 79
Mukul Ram
  • 356
  • 4
  • 14
  • 2
    Is your "select.rs" actually [this crate](https://docs.rs/select/0.4.2/select/)? Why do you call it select.rs then? – hellow Apr 18 '19 at 05:47
  • Possible duplicate of [How do I use Rayon with an existing iterator?](https://stackoverflow.com/questions/48922420/how-do-i-use-rayon-with-an-existing-iterator) – lovasoa Apr 18 '19 at 08:44
  • See https://docs.rs/rayon/1.0.2/rayon/prelude/trait.ParallelBridge.html – lovasoa Apr 18 '19 at 08:45
  • @hellow that's what I got from Github, sorry. I believe it is that crate as well. https://github.com/utkarshkukreti/select.rs – Mukul Ram Apr 18 '19 at 23:15
  • I wasn't sure how to get the parallel bridge working. Would you mind putting together a quick example? – Mukul Ram Apr 18 '19 at 23:16

0 Answers0