orx_parallel/using/
using_variants.rs1pub trait Using {
6 type Item: Send;
8
9 fn create(&mut self, thread_idx: usize) -> Self::Item;
11
12 fn into_inner(self) -> Self::Item;
14}
15
16pub struct UsingClone<T: Clone + Send>(T);
18
19impl<T: Clone + Send> UsingClone<T> {
20 pub(crate) fn new(value: T) -> Self {
21 Self(value)
22 }
23}
24
25impl<T: Clone + Send> Using for UsingClone<T> {
26 type Item = T;
27
28 fn create(&mut self, _: usize) -> T {
29 self.0.clone()
30 }
31
32 fn into_inner(self) -> Self::Item {
33 self.0
34 }
35}
36
37pub struct UsingFun<F, T>
39where
40 T: Send,
41 F: FnMut(usize) -> T,
42{
43 fun: F,
44}
45
46impl<F, T> UsingFun<F, T>
47where
48 T: Send,
49 F: FnMut(usize) -> T,
50{
51 pub(crate) fn new(fun: F) -> Self {
52 Self { fun }
53 }
54}
55
56impl<F, T> Using for UsingFun<F, T>
57where
58 T: Send,
59 F: FnMut(usize) -> T,
60{
61 type Item = T;
62
63 fn create(&mut self, thread_idx: usize) -> Self::Item {
64 (self.fun)(thread_idx)
65 }
66
67 fn into_inner(mut self) -> Self::Item {
68 (self.fun)(0)
69 }
70}