i'm trying to parallelize the following function:
pub fn encode(&self, s: &String) -> String {
s.chars()
.par_iter() // error here
.map(|c| Character::try_from(c))
.enumerate()
.map(|(n, c)| match c {
Ok(plain) => self.encode_at(plain, n).into(),
Err(e) => match e {
ParsingError::Charset(non_alphabetic) => non_alphabetic,
_ => unreachable!(),
},
})
.collect()
}
I get the following error when trying to go from the Chars iterator into a parallel iterator:
the method
par_iter
exists for structstd::str::Chars<'_>
, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
&std::str::Chars<'_>: IntoParallelIterator
which is required bystd::str::Chars<'_>: rayon::iter::IntoParallelRefIterator
rustcE0599
I would expect that converting an iterator into a parallel iterator would be fairly trivial but apparently not