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 {
29 type Output: Send;
30 type Future: Future<Output = Self::Output> + Send;
31
32 fn call(self) -> Self::Future;
34}
35
36impl<F, Fut, O> AsyncRecoverableFunction for F
37where
38 F: FnOnce() -> Fut + Send + Sync + 'static,
39 Fut: Future<Output = O> + Send + 'static,
40 O: Send + 'static,
41{
42 type Output = O;
43 type Future = Fut;
44
45 fn call(self) -> Self::Future {
46 self()
47 }
48}
49
50pub trait AsyncErrorHandlerFunction: Send + Sync + 'static {
55 type Future: Future<Output = ()> + Send;
56
57 fn call(self, error: Arc<String>) -> Self::Future;
61}
62
63impl<F, Fut> AsyncErrorHandlerFunction for F
64where
65 F: FnOnce(Arc<String>) -> Fut + Send + Sync + 'static,
66 Fut: Future<Output = ()> + Send + 'static,
67{
68 type Future = Fut;
69
70 fn call(self, error: Arc<String>) -> Self::Future {
71 self(error)
72 }
73}
74
75pub trait RecoverableFunction: FnOnce() + Send + Sync + 'static {}
79
80impl<T> RecoverableFunction for T where T: FnOnce() + Send + Sync + 'static {}
81
82pub trait ErrorHandlerFunction: FnOnce(&str) + Send + Sync + 'static {}
87
88impl<T> ErrorHandlerFunction for T where T: FnOnce(&str) + Send + Sync + 'static {}