use std::any::Any;
use std::sync::Arc;
use super::{
Bootable, ComponentOrder, Finalizable, Reloadable, Resolve, Result,
Runnable, RunnableInstance,
};
pub trait Component<S>: Any + Send + Sync {
type Deps: Resolve<S>;
fn name(&self) -> &str;
fn boot_priority(&self) -> Option<u8> {
None
}
fn run_priority(&self) -> Option<u8> {
None
}
fn order(&self) -> ComponentOrder {
ComponentOrder::default()
}
fn as_bootable(&self) -> Option<&dyn Bootable<S, Self::Deps>> {
None
}
fn validate(
&self,
_state: &S,
) -> Result<()> {
Ok(())
}
fn as_any(&self) -> &dyn Any
where
Self: Sized,
{
self
}
fn as_reloadable(&self) -> Option<&dyn Reloadable<S>> {
None
}
#[cfg(feature = "fleet")]
fn as_scoped(&self) -> Option<&dyn crate::fleet::Scoped> {
None
}
#[cfg(feature = "fleet")]
fn as_dispatched(&self) -> Option<&dyn crate::fleet::Dispatched> {
None
}
#[cfg(feature = "config")]
fn as_configurable(&self) -> Option<&dyn congif::ConfigRegistration> {
None
}
#[cfg(feature = "config")]
fn as_environmental(&self) -> Option<&dyn congif::Environmental> {
None
}
fn as_finalizable(&self) -> Option<&dyn Finalizable<S>> {
None
}
fn as_runnable(
self: Arc<Self>
) -> Option<Arc<dyn Runnable<S, Self::Deps>>> {
None
}
fn runnables(self: Arc<Self>) -> Vec<RunnableInstance<S>>
where
S: Send + Sync + 'static,
{
self.clone()
.as_runnable()
.map(|runnable| RunnableInstance::new(self.name(), runnable))
.into_iter()
.collect()
}
}