redup-abstractions 0.3.4

Контракты состояния службы: здоровье модуля, зависимость и зонд.
Documentation
//! Состояние элемента на момент чтения.

use crate::phase::Phase;
use crate::problem::Problem;

/// Фаза и проблемы элемента на момент чтения.
#[derive(Debug, Clone)]
pub struct HealthSnapshot {
    phase: Phase,
    problems: Vec<Problem>,
}

impl HealthSnapshot {
    pub(crate) fn new(phase: Phase, problems: Vec<Problem>) -> Self {
        Self { phase, problems }
    }

    /// Фаза с учётом зависимостей.
    pub fn phase(&self) -> Phase {
        self.phase
    }

    /// Проблемы: главные, заявленные модулем и от зависимостей.
    pub fn problems(&self) -> &[Problem] {
        &self.problems
    }

    /// Работает, но с проблемами.
    pub fn is_degraded(&self) -> bool {
        self.phase.is_serving() && !self.problems.is_empty()
    }
}

impl PartialEq for HealthSnapshot {
    fn eq(&self, other: &Self) -> bool {
        self.phase == other.phase && self.problems == other.problems
    }
}

impl Eq for HealthSnapshot {}