capitan_lib/services/
dynamic.rs1use std::sync::Arc;
2
3use async_trait::async_trait;
4
5use anyhow::Result as Res;
6
7use super::{isolated::IsolatedService, shared::SharedService};
8
9pub struct DynamicIsolatedService(pub(crate) Box<dyn IsolatedService + Send + Sync>);
10pub struct DynamicSharedService(pub(crate) Arc<dyn SharedService + Send + Sync>);
11
12#[async_trait]
13impl IsolatedService for DynamicIsolatedService {
14 async fn init(&mut self) -> Res<()> {
15 self.0.init().await?;
16 Ok(())
17 }
18
19 async fn main(&mut self) -> Res<()> {
20 self.0.main().await?;
21 Ok(())
22 }
23
24 async fn repeat(&mut self) -> Res<()> {
25 self.0.repeat().await?;
26 Ok(())
27 }
28
29 async fn catch(&mut self, error: anyhow::Error) -> Res<()> {
30 self.0.catch(error).await?;
31 Ok(())
32 }
33
34 async fn abort(&mut self, error: anyhow::Error) -> Res<()> {
35 self.0.abort(error).await?;
36 Ok(())
37 }
38}
39
40#[async_trait]
41impl SharedService for DynamicSharedService {
42 async fn init(&self) -> Res<()> {
43 self.0.init().await?;
44 Ok(())
45 }
46
47 async fn main(&self) -> Res<()> {
48 self.0.main().await?;
49 Ok(())
50 }
51
52 async fn repeat(&self) -> Res<()> {
53 self.0.repeat().await?;
54 Ok(())
55 }
56
57 async fn catch(&self, error: anyhow::Error) -> Res<()> {
58 self.0.catch(error).await?;
59 Ok(())
60 }
61
62 async fn abort(&self, error: anyhow::Error) -> Res<()> {
63 self.0.abort(error).await?;
64 Ok(())
65 }
66}