1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// 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`](crate::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]);
/// ```