recoverable_spawn/thread/
trait.rs1use std::{future::Future, sync::Arc};
2
3pub trait FunctionOnceTrait: FnOnce() + Send + Sync + 'static {}
7
8impl<T> FunctionOnceTrait for T where T: FnOnce() + Send + Sync + 'static {}
9
10pub trait FunctionTrait: Fn() + Send + Sync + 'static {}
14
15impl<T> FunctionTrait for T where T: Fn() + Send + Sync + 'static {}
16
17pub trait FunctionMutTrait: FnMut() + Send + Sync + 'static {}
21
22impl<T> FunctionMutTrait for T where T: FnMut() + Send + Sync + 'static {}
23
24pub trait AsyncRecoverableFunction: Send + Sync + 'static {
34 type Output: Send;
35 type Future: Future<Output = Self::Output> + Send;
36
37 fn call(self) -> Self::Future;
39}
40
41impl<F, Fut, O> AsyncRecoverableFunction for F
42where
43 F: FnOnce() -> Fut + Send + Sync + 'static,
44 Fut: Future<Output = O> + Send + 'static,
45 O: Send + 'static,
46{
47 type Output = O;
48 type Future = Fut;
49
50 fn call(self) -> Self::Future {
51 self()
52 }
53}
54
55pub trait AsyncErrorHandlerFunction: Send + Sync + 'static {
65 type Future: Future<Output = ()> + Send;
66
67 fn call(self, error: Arc<String>) -> Self::Future;
71}
72
73impl<F, Fut> AsyncErrorHandlerFunction for F
74where
75 F: FnOnce(Arc<String>) -> Fut + Send + Sync + 'static,
76 Fut: Future<Output = ()> + Send + 'static,
77{
78 type Future = Fut;
79
80 fn call(self, error: Arc<String>) -> Self::Future {
81 self(error)
82 }
83}
84
85pub trait RecoverableFunction: FnOnce() + Send + Sync + 'static {}
89
90impl<T> RecoverableFunction for T where T: FnOnce() + Send + Sync + 'static {}
91
92pub trait ErrorHandlerFunction: FnOnce(&str) + Send + Sync + 'static {}
98
99impl<T> ErrorHandlerFunction for T where T: FnOnce(&str) + Send + Sync + 'static {}