Expand description
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 rayon::iter::IntoParallelIterator as _;
use rayon::iter::ParallelIterator as _;
use dynqueue::IntoDynQueue as _;
let mut result = vec![1, 2, 3]
.into_dyn_queue()
.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
ⓘ
use dynqueue::{DynQueue, DynQueueHandle, IntoDynQueue};
use rayon::iter::IntoParallelIterator as _;
use rayon::iter::ParallelIterator as _;
use std::sync::RwLock;
static mut STALE_HANDLE: Option<DynQueueHandle<u8, RwLock<Vec<u8>>>> = None;
pub fn test_func() -> Vec<u8> {
vec![1u8, 2u8, 3u8]
.into_dyn_queue()
.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 - DynQueue
Handle - The
DynQueueHandle
returned by the iterator in addition toT
Traits§
- Into
DynQueue - Trait to produce a new DynQueue
- Queue
- Everything implementing
Queue
can be handled by DynQueue