capability-grower-configuration-comparison 0.1.0

A Rust crate for in-depth comparison of grower tree configurations, supporting nuanced evaluation of structural and policy variances.
Documentation
// ---------------- [ File: capability-grower-configuration-comparison/src/compare_outcome.rs ]
crate::ix!();

#[derive(Debug, Clone, PartialEq)]
pub enum CompareOutcome {
    /// Perfect or near-perfect match (score=1.0).
    Exact,
    /// Partial or probabilistic match, with a numeric [0..1] score.
    Partial(f32),
    /// A definite mismatch or violation of a hard constraint.
    Incompatible,
}

impl CompareOutcome {
    /// Multiplicative combination approach for partial checks
    pub fn combine(&self, other: &CompareOutcome) -> CompareOutcome {
        use CompareOutcome::*;
        match (self, other) {
            (Incompatible, _) | (_, Incompatible) => Incompatible,
            (Exact, Exact) => Exact,
            (Exact, Partial(x)) => Partial(*x),
            (Partial(x), Exact) => Partial(*x),
            (Partial(a), Partial(b)) => {
                let combined = a * b;
                Partial(combined)
            }
        }
    }

    /// Converts an outcome to a numeric [0..1].
    pub fn to_score(&self) -> f32 {
        match self {
            CompareOutcome::Incompatible => 0.0,
            CompareOutcome::Exact => 1.0,
            CompareOutcome::Partial(x) => *x,
        }
    }

    /// A convenience for checking equality with `CompareOutcome::Exact`
    pub fn is_exact(&self) -> bool {
        matches!(self, CompareOutcome::Exact)
    }

    /// A convenience for checking if self is `Incompatible`.
    pub fn is_incompatible(&self) -> bool {
        matches!(self, CompareOutcome::Incompatible)
    }
}