ayun_core/traits/
application.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{traits::ServiceTrait, Container, Result};

pub trait ApplicationTrait: Default {
    #[cfg(feature = "migration")]
    type Migrator: sea_orm_migration::MigratorTrait;

    #[cfg(any(feature = "http1", feature = "http2"))]
    fn with_routing() -> impl ServiceTrait;

    #[cfg(feature = "schedule")]
    fn with_schedule() -> impl ServiceTrait;

    #[cfg(feature = "console")]
    fn with_console() -> impl ServiceTrait;

    fn register(container: Container) -> Result<Container> {
        Ok(container)
    }

    fn boot() {
        #[cfg(not(feature = "logger"))]
        {
            use tracing_subscriber::layer::SubscriberExt;

            let subscriber = tracing_subscriber::registry()
                .with(tracing_subscriber::fmt::layer().with_target(false));
            let _ = tracing::subscriber::set_global_default(subscriber);
        }

        #[cfg(feature = "color-eyre")]
        color_eyre::install().expect("Failed to install color eyre");
    }

    fn new() -> Self {
        Self::default()
    }

    fn run<S: ServiceTrait>(self) -> Result<()>
    where
        Self: Sized,
    {
        S::init::<Self>().run()
    }
}