ayun_core/traits/
application.rs

1use crate::{support::Container, traits::ServiceTrait, Result};
2
3pub trait ApplicationTrait: Default {
4    #[cfg(feature = "migration")]
5    type Migrator: sea_orm_migration::MigratorTrait;
6
7    #[cfg(feature = "server")]
8    fn with_routing() -> impl ServiceTrait;
9
10    #[cfg(feature = "schedule")]
11    fn with_schedule() -> impl ServiceTrait;
12
13    #[cfg(feature = "console")]
14    fn with_console() -> impl ServiceTrait;
15
16    #[cfg(feature = "worker")]
17    fn with_worker() -> impl ServiceTrait;
18
19    fn register(container: Container) -> Result<Container> {
20        Ok(container)
21    }
22
23    fn boot() {
24        #[cfg(not(feature = "tracing"))]
25        {
26            use tracing_subscriber::layer::SubscriberExt;
27
28            let subscriber = tracing_subscriber::registry()
29                .with(tracing_subscriber::fmt::layer().with_target(false));
30            let _ = tracing::subscriber::set_global_default(subscriber);
31        }
32
33        #[cfg(feature = "color-eyre")]
34        color_eyre::install().expect("Failed to install color eyre");
35    }
36
37    fn new() -> Self {
38        Self::default()
39    }
40
41    fn run<S: ServiceTrait>(self) -> Result<()>
42    where
43        Self: Sized,
44    {
45        S::init::<Self>().run()
46    }
47}