async_map_reduce/
entities.rs1use std::any::Any;
2use std::thread::JoinHandle;
3
4pub type ThreadError = Box<dyn Any + Send + 'static>;
5pub enum MapReduceError<E> {
6 ThreadFailed(ThreadError),
7 Custom(E),
8}
9
10pub(crate) struct CtxWrapper {
11 data: *const u8,
12}
13
14impl Clone for CtxWrapper {
15 fn clone(&self) -> Self {
16 CtxWrapper { data: self.data }
17 }
18}
19
20impl Copy for CtxWrapper {}
21
22unsafe impl Send for CtxWrapper {}
23unsafe impl Sync for CtxWrapper {}
24
25impl CtxWrapper {
26 pub fn new<T>(value: &T) -> CtxWrapper {
27 CtxWrapper {
28 data: value as *const T as *const u8,
29 }
30 }
31
32 pub fn get<T>(&self) -> &T {
33 unsafe { &*(self.data as *const T) }
34 }
35}
36
37pub(crate) struct Worker<Resp> {
38 pub thread: Box<JoinHandle<Resp>>,
39}
40
41pub(crate) struct ResWrapper<T> {
42 data: Box<T>,
43}
44
45unsafe impl<T> Send for ResWrapper<T> {}
46unsafe impl<T> Sync for ResWrapper<T> {}
47
48impl<T> ResWrapper<T> {
49 pub(crate) fn new(val: T) -> Self {
50 Self {
51 data: Box::new(val),
52 }
53 }
54
55 pub(crate) fn get(self) -> T {
56 *self.data
57 }
58}