1use std::pin::Pin;
2
3use crate::prelude::*;
4#[allow(refining_impl_trait)]
6pub trait Handler: Send + Sync {
7 const QUEUE: &'static str;
8
9 fn process(
20 &self,
21 queue: &SimpleQueue,
22 job: &Job,
23 ) -> impl Future<Output = Result<JobResult, BoxDynError>> + Send;
24
25 fn queue(&self) -> &'static str {
27 Self::QUEUE
28 }
29}
30
31pub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
32pub(crate) trait DynJobHandler: Send + Sync {
33 fn process_dyn<'a>(
34 &'a self,
35 queue: &'a SimpleQueue,
36 job: &'a Job,
37 ) -> BoxFuture<'a, Result<JobResult, BoxDynError>>;
38}
39
40impl<T: Handler> DynJobHandler for T {
41 fn process_dyn<'a>(
42 &'a self,
43 queue: &'a SimpleQueue,
44 job: &'a Job,
45 ) -> BoxFuture<'a, Result<JobResult, BoxDynError>> {
46 Box::pin(self.process(queue, job))
47 }
48}