[][src]Crate dynqueue

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.

Example

use dynqueue::{DynQueue, DynQueueHandle};

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

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]);

Panics

The DynQueueHandle shall not outlive the DynQueue iterator

This example panics
use dynqueue::{DynQueue, DynQueueHandle};

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

static mut STALE_HANDLE : Option<DynQueueHandle<u8, Vec<u8>>> = None;

pub fn test_func() -> Vec<u8> {
    DynQueue::new(vec![1u8, 2u8, 3u8])
        .into_par_iter()
        .map(|(handle, value)| unsafe { STALE_HANDLE.replace(handle); value })
        .collect::<Vec<_>>()
}
// test_func() panics
let result = test_func();
unsafe { STALE_HANDLE.as_ref().unwrap().enqueue(4); }

Structs

DynQueue

The DynQueue<T> which can be parallel iterated over

DynQueueHandle

The DynQueueHandle returned by the iterator in addition to T

Traits

Queue

Everything implementing Queue can be handled by DynQueue