vers3 0.2.0

Explicit-state model checking library
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2026, Marco Elver <me@marcoelver.com>

//! `vers3` — Explicit-State Model Checking Library
//!
//! # Quick start
//!
//! ```
//! use vers3::{TransitionSystem, invariant, rule, search::Bfs};
//!
//! // 1. Define your state (Clone + Hash + Eq + Display = State automatically).
//! #[derive(Clone, Hash, PartialEq, Eq, Debug)]
//! struct Counter(u32);
//! vers3::display_via_debug!(Counter);
//!
//! // 2. Build a transition system: guarded rules plus safety invariants.
//! let mut ts = TransitionSystem::new();
//! ts.add_rule(rule(
//!     "increment",
//!     |_: &Counter| true,
//!     |s: &mut Counter| {
//!         s.0 = (s.0 + 1) % 4; // wrap around: the state space is finite
//!         true
//!     },
//! ));
//! ts.add_property(invariant("bounded", |s: &Counter| s.0 < 4));
//!
//! // 3. Run BFS (ts is consumed, preventing reuse with stale property state).
//! let result = Bfs::new().run(vec![Counter(0)], ts);
//! match &result {
//!     Ok(stats) => println!("No violations. {stats}"),
//!     Err(cex) => vers3::report::print_counterexample(cex),
//! }
//! # assert_eq!(result.unwrap().states_visited, 4);
//! ```

#![forbid(unsafe_code)]
#![warn(missing_docs)]

/// Implement [`std::fmt::Display`] for a type by delegating to its [`std::fmt::Debug`] impl.
///
/// Useful for simple enums that `#[derive(Debug)]` and need no custom `Display`.
///
/// # Example
///
/// ```
/// #[derive(Debug)]
/// enum Color { Red, Green, Blue }
///
/// vers3::display_via_debug!(Color);
/// assert_eq!(format!("{}", Color::Red), "Red");
/// ```
#[macro_export]
macro_rules! display_via_debug {
    ($ty:ty) => {
        impl ::std::fmt::Display for $ty {
            fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
                write!(f, "{self:?}")
            }
        }
    };
}

// Compile the README's Rust examples as doctests.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;

pub mod properties;
pub mod report;
pub mod search;
pub mod ts;
pub mod types;
pub mod util;

pub use ts::{
    CheckerError, InvariantFn, Property, Rule, RuleError, RuleFn, State, Stepping,
    TransitionSysSimulation, TransitionSystem, Unknown, Unknowns, error_if, invariant, rule,
    rule_try,
};
pub use types::{ArraySet, StateHash, combine_hash};