This is a contrived example but I believe if I can get this working I can apply it to my specific case.
extern crate num;
extern crate rayon;
use rayon::prelude::*;
use num::Float;
fn sqrts<T: Float>(floats: &Vec<T>) -> Vec<T> {
floats.par_iter().map(|f| f.sqrt()).collect()
}
fn main() {
let v = vec![1.0, 4.0, 9.0, 16.0, 25.0];
println!("{:?}", sqrts(&v));
}
This errors at compile time with "the method par_iter
exists but the following trait bounds were not satisfied: &std::vec::Vec<T> : rayon::par_iter::IntoParallelIterator
". The code works fine if I use iter
instead of par_iter
or if I switch to using f32
or f64
instead of the generic.
What can I do to be able to use par_iter
on a vector of generics? Is the IntoParallelIterator
trait meant to be implemented by the end user? How would I go about doing that?