koala-core 1.0.4

Shared types, invariant evaluator, and primitives for the koala framework.
Documentation
//! Invariant evaluator. See ADR-0013.

mod context;
mod outcome;
mod perf;
mod property;
mod registry;
pub mod rules;
mod user_toml;

pub use context::Context;
pub use outcome::Outcome;
pub use perf::{evaluate_against_baseline, Baseline, PerfDecision};
pub use property::{persist_counter_example, persisted_path, PersistError, PropertyResult};
pub use registry::Registry;
pub use user_toml::{
    load_all as load_user_invariants, LoadError as UserLoadError, UserDefinedInvariant,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Category {
    Arch,
    Deps,
    Docs,
    Security,
    Health,
    Governance,
}

impl Category {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Arch => "arch",
            Self::Deps => "deps",
            Self::Docs => "docs",
            Self::Security => "security",
            Self::Health => "health",
            Self::Governance => "governance",
        }
    }
}

pub trait Invariant: Send + Sync {
    fn id(&self) -> &'static str;
    fn category(&self) -> Category;
    fn intent(&self) -> &'static str;
    fn adr(&self) -> Option<&'static str> {
        None
    }
    fn evaluate(&self, ctx: &Context) -> Outcome;
}