#![allow(unused_variables)]
mod name;
mod registry;
pub use self::{name::Name, registry::Registry};
use crate::{application::Application, error::FrameworkError, shutdown::Shutdown, Version};
use std::{cmp::Ordering, fmt::Debug, slice::Iter};
pub trait Component<A>: Debug + Send + Sync
where
A: Application,
{
fn name(&self) -> Name;
fn version(&self) -> Version;
fn dependencies(&self) -> Iter<'_, Name> {
[].iter()
}
fn after_config(&mut self, config: &A::Cfg) -> Result<(), FrameworkError> {
Ok(())
}
fn before_shutdown(&self, kind: Shutdown) -> Result<(), FrameworkError> {
Ok(())
}
}
impl<A> PartialEq for Box<dyn Component<A>>
where
A: Application,
{
fn eq(&self, other: &Self) -> bool {
self.name() == other.name()
}
}
impl<A> PartialOrd for Box<dyn Component<A>>
where
A: Application,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if other.dependencies().any(|dep| *dep == self.name()) {
if self.dependencies().any(|dep| *dep == other.name()) {
None
} else {
Some(Ordering::Greater)
}
} else if self.dependencies().any(|dep| *dep == other.name()) {
Some(Ordering::Less)
} else {
Some(Ordering::Equal)
}
}
}