Edit: I'm adding this note after getting some useful replies and changing the Github repository for this project quite a bit. Knowing this, if you're interested, you should be able to follow what I changed and learned.
I hope nobody thinks I'm spamming by sharing my work on Github. It seemed the easiest way to demonstrate my problem. Believe me, I've been reading around all day trying to figure this out.
GitHub - suchapalaver/krust: k-mer counter in Rust using the rust-bio and rayon crates is an implementation in Rust of a kmer counter, a common tool in bioinformatics for analyzing DNA sequences. The files used for the relevant data often contain multiple sequences of data, so the task is given to parallelization/cocurrency/multithreadedness.
I have three branches in this repo -- main, single_thread, and rayonizing.
- main compiles and works and provides cocurrent processing using
std::thread
. - single_thread just uses a single thread to complete everything and works and compiles.
- rayonizing, which I hoped would do exactly what main does but with rayon, gives me the following error:
the method `into_par_iter` exists for struct `bio::io::fasta::Records<BufReader<File>>`, but its trait bounds were not satisfied
--> src/lib.rs:47:22
|
47 | reader.records().into_par_iter().for_each(|result| {
| ^^^^^^^^^^^^^ method cannot be called on `bio::io::fasta::Records<BufReader<File>>` due to unsatisfied trait bounds
|
::: /home/jojo/.cargo/registry/src/github.com-1ecc6299db9ec823/bio-0.37.1/src/io/fasta.rs:1015:1
|
1015 | / pub struct Records<B>
1016 | | where
1017 | | B: io::BufRead,
1018 | | {
1019 | | reader: Reader<B>,
1020 | | error_has_occured: bool,
1021 | | }
| | -
| | |
| |_doesn't satisfy `_: rayon::iter::IntoParallelIterator`
| doesn't satisfy `_: rayon::iter::ParallelIterator`
|
= note: the following trait bounds were not satisfied:
`bio::io::fasta::Records<BufReader<File>>: rayon::iter::ParallelIterator`
which is required by `bio::io::fasta::Records<BufReader<File>>: rayon::iter::IntoParallelIterator`
`&bio::io::fasta::Records<BufReader<File>>: rayon::iter::ParallelIterator`
which is required by `&bio::io::fasta::Records<BufReader<File>>: rayon::iter::IntoParallelIterator`
`&mut bio::io::fasta::Records<BufReader<File>>: rayon::iter::ParallelIterator`
which is required by `&mut bio::io::fasta::Records<BufReader<File>>: rayon::iter::IntoParallelIterator`
The part of the code in question that I changed in order to get the error is this part quoted in the error message, here from the rayonizing branch of my repository, src/lib.rs:
let reader = fasta::Reader::from_file(&filepath).unwrap();
reader.records().into_par_iter().for_each(|result| {
let result_data = result.unwrap();
Please note that Send
and Sync
are Auto Trait Implementations for the Struct bio::io::fasta::Reader
that I am using from the rust-bio
crate (https://docs.rs/bio/0.20.3/bio/io/fasta/struct.Reader.html#method.records), and for its records
method (bio::io::fasta::Reader - Rust).
I'm new this year to programming in general, since January, and this is my first program in Rust. Thank you for any help!