use crate::module::ModuleInterface;
use crate::Module;
use crate::ModuleBuildContext;
use std::any::Any;
use std::sync::Arc;
pub trait Component<M: Module>: Interface {
type Interface: Interface + ?Sized;
#[cfg(feature = "thread_safe")]
type Parameters: Default + Send;
#[cfg(not(feature = "thread_safe"))]
type Parameters: Default;
fn build(context: &mut ModuleBuildContext<M>, params: Self::Parameters)
-> Box<Self::Interface>;
}
#[cfg(not(feature = "thread_safe"))]
trait_alias!(
pub Interface = Any
);
#[cfg(feature = "thread_safe")]
trait_alias!(
pub Interface = Any + Send + Sync
);
#[cfg(not(feature = "thread_safe"))]
pub type ComponentFn<M, I> = Box<dyn FnOnce(&mut ModuleBuildContext<M>) -> Box<I>>;
#[cfg(feature = "thread_safe")]
pub type ComponentFn<M, I> = Box<dyn (FnOnce(&mut ModuleBuildContext<M>) -> Box<I>) + Send + Sync>;
pub trait HasComponent<I: Interface + ?Sized>: ModuleInterface {
fn build_component(context: &mut ModuleBuildContext<Self>) -> Arc<I>
where
Self: Module + Sized;
fn resolve(&self) -> Arc<I>;
fn resolve_ref(&self) -> &I;
}