pub trait Use: Sync {
type Item: Send;
// Required methods
unsafe fn init_get(&self, thread_idx: usize) -> &mut Self::Item;
fn get(&mut self, thread_idx: usize) -> &mut Self::Item;
fn max_threads(&self) -> Option<usize>;
}Expand description
Worker-local mutable state used by parallel iterators.
A Use value provides one mutable slot per participating worker thread.
Parallel combinators initialize the slot for a thread on first access and
then reuse it for subsequent accesses from the same thread.
UseVec is the owned implementation of this trait in this crate.
§Examples
use orx_parallel::{Use, UseVec};
fn bump_first_thread<U: Use<Item = usize>>(use_var: &mut U) -> usize {
*unsafe { use_var.init_get(0) } += 1;
*use_var.get(0)
}
let mut use_vec = UseVec::new(|_| 0usize);
assert_eq!(bump_first_thread(&mut use_vec), 1);
assert_eq!(use_vec.into_vec(), vec![1]);Required Associated Types§
Required Methods§
Sourceunsafe fn init_get(&self, thread_idx: usize) -> &mut Self::Item
unsafe fn init_get(&self, thread_idx: usize) -> &mut Self::Item
Returns the mutable worker-local value for thread_idx, creating it if needed.
§SAFETY
Must be called only once per thread.
Sourcefn max_threads(&self) -> Option<usize>
fn max_threads(&self) -> Option<usize>
Returns an upper bound on the number of worker threads that may use this value.
None means the implementation does not impose a fixed upper bound.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".