Skip to main content

Crate invars

Crate invars 

Source
Expand description

§Invars

Invars is a declarative data validation engine for Rust.

It allows you to define invariants (validation rules) and evaluate them against a dataset using an execution engine (currently Polars).


§Core Concepts

  • Invariant: A validation rule (e.g. “column must be unique”).
  • Scope: Where the rule applies (Dataset or Column).
  • Engine: Executes invariants against data.
  • Violation: Returned when an invariant fails.

Execution model:

Invariant
   ↓
plan() -> Metric Expression
   ↓
Engine execution (Polars LazyFrame)
   ↓
map() -> Option<Violation>

§Quick Example (Polars)

§#[cfg(feature = “polars”)]

§fn main() -> Result<(), Box> {

use invars::prelude::; use polars::prelude::;

let df = df! { “age” => [18, 25, 130], }?;

let invariant = Invariant::new( “age_between”.to_string().try_into()?, PolarsKind::ValueBetween, Scope::Column { name: “age”.into() }, ) .with_param(“min”, “0”) .with_param(“max”, “120”);

let engine = EnginePolarsDataFrame::default(); let violations = engine.evaluate(&df, vec![invariant])?;

Ok(())

§}

§

§#[cfg(not(feature = “polars”))]

§fn main() {}


§Feature Flags

  • polars — Enables the Polars execution engine.

§Design Goals

  • Declarative validation rules
  • Engine-agnostic core domain
  • Lazy execution support
  • Explicit metric-to-violation mapping
  • Fully testable invariant units

Invars is designed to be predictable, extensible, and AI-friendly.

Modules§

engine
error
infrastructure
interface
invariant
prelude
report
scope
severity
spec
use_cases
violation