use std::sync::Arc;
use crate::{CordisError, FiberState, InstanceId, PluginId, ServiceReadFailure, TypeKey};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RuntimeDiagnostics {
pub shutting_down: bool,
pub plugins: Vec<PluginDiagnostics>,
pub bindings: Vec<BindingDiagnostics>,
pub event_backlogs: Vec<EventBacklog>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct EventBacklog {
pub key: TypeKey,
pub pending: usize,
pub oldest: std::time::Duration,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct PluginDiagnostics {
pub id: PluginId,
pub instance: InstanceId,
pub parent: Option<PluginId>,
pub name: String,
pub state: FiberState,
pub generation: u64,
pub error: Option<Arc<CordisError>>,
pub injects: Vec<DependencyDiagnostics>,
pub resolved_dependencies: Vec<ResolvedDependency>,
pub accesses: Vec<ServiceAccess>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct DependencyDiagnostics {
pub key: TypeKey,
pub scope: Option<String>,
pub status: DependencyStatus,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DependencyStatus {
OutOfScope,
Missing,
Removing,
ProviderInactive(FiberState),
CheckPending,
CheckRejected,
CheckPanicked,
Ready,
}
impl std::fmt::Display for DependencyStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::OutOfScope => f.write_str("instance out of scope"),
Self::Missing => f.write_str("service missing"),
Self::Removing => f.write_str("service being removed"),
Self::ProviderInactive(state) => write!(f, "provider inactive ({state:?})"),
Self::CheckPending => f.write_str("check pending"),
Self::CheckRejected => f.write_str("check rejected"),
Self::CheckPanicked => f.write_str("check panicked"),
Self::Ready => f.write_str("ready"),
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ResolvedDependency {
pub key: TypeKey,
pub scope: Option<String>,
pub provider: PluginId,
pub generation: u64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ServiceAccess {
pub key: TypeKey,
pub scope: Option<String>,
pub provider: Option<PluginId>,
pub generation: Option<u64>,
pub declared: bool,
pub external: bool,
pub out_of_scope: bool,
pub strict: bool,
pub failure: Option<ServiceReadFailure>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct BindingDiagnostics {
pub key: TypeKey,
pub scope: Option<String>,
pub provider: PluginId,
pub generation: u64,
pub removing: bool,
}