ayun-core 0.24.0

The RUST Framework for Web Rustceans.
Documentation
use crate::{
    error::ContainerError,
    support::{app, type_name, Container},
    Result,
};

pub trait InstanceTrait: std::any::Any + Send + Sync {
    fn name() -> String {
        type_name::<Self>()
    }

    fn register(container: &Container) -> Result<Self, ContainerError>
    where
        Self: Sized;

    fn boot() -> Result<(), ContainerError>
    where
        Self: Sized,
    {
        Ok(())
    }

    fn cleanup() -> Result<(), ContainerError> {
        Ok(())
    }

    fn facade() -> &'static Self
    where
        Self: Sized,
    {
        app()
            .resolve::<Self>()
            .unwrap_or_else(|err| panic!("{err}"))
    }
}