dynamically extendable Rayon parallel iterator
Find a file
2020-05-26 00:32:03 +02:00
.github/workflows initial commit 2020-05-26 00:32:03 +02:00
src initial commit 2020-05-26 00:32:03 +02:00
.gitignore initial commit 2020-05-26 00:32:03 +02:00
Cargo.toml initial commit 2020-05-26 00:32:03 +02:00
LICENSE initial commit 2020-05-26 00:32:03 +02:00
README.md initial commit 2020-05-26 00:32:03 +02:00

DynQueue - dynamically extendable Rayon parallel iterator

A DynQueue<T> can be iterated with into_par_iter producing (DynQueueHandle, T) elements. With the DynQueueHandle<T> a new T can be inserted in the DynQueue<T>, which is currently iterated over.

use dynqueue::DynQueue;

use rayon::iter::IntoParallelIterator as _;
use rayon::iter::ParallelIterator as _;

fn main() {
    let mut result = DynQueue::new(vec![1, 2, 3])
                         .into_par_iter()
                         .map(|(handle, value)| { if value == 2 { handle.enqueue(4) }; value })
                         .collect::<Vec<_>>();
    result.sort();

    assert_eq!(result, vec![1, 2, 3, 4]);
}