rmpca 0.1.1

Enterprise-grade route optimization engine — Chinese Postman Problem solver with Eulerian circuit detection, Lean 4 FFI boundary, and property-based testing
Documentation
//! Domain-specific error types for the route optimization engine.
//!
//! // Aligns with Lean4: These errors correspond to preconditions that
//! must hold for the theorems in the formal specification.
//!
//! Per project conventions, anyhow is reserved for application boundaries
//! (CLI entry points). All library code within the optimizer module uses
//! thiserror-based domain error types.

use thiserror::Error;

/// Domain error type for all route optimization operations.
///
/// Every variant captures the full context required to diagnose the failure:
/// which node, which edge, what graph state caused the problem.
// Aligns with Lean4: each variant represents a violated precondition
#[allow(dead_code)]
#[derive(Debug, Error)]
pub enum RouteError {
    /// A graph operation was attempted on an empty graph.
    #[error("graph is empty — no nodes available for optimization")]
    EmptyGraph,

    /// An edge expected to exist between two nodes was not found.
    #[error("missing edge from node {from} to node {to}")]
    MissingEdge {
        from: usize,
        to: usize,
    },

    /// The graph is not Eulerian: a node has mismatched in/out degrees.
    #[error(
        "graph is not Eulerian: node {node_id} has in-degree {in_degree} and out-degree {out_degree}"
    )]
    NotEulerian {
        node_id: String,
        in_degree: usize,
        out_degree: usize,
    },

    /// The graph has no strongly connected components.
    #[error("graph has no strongly connected components")]
    NoStronglyConnectedComponent,

    /// `GeoJSON` parsing or structure error.
    #[error("malformed route data at node {node_id}: {reason}")]
    MalformedRouteData {
        node_id: String,
        reason: String,
    },

    /// A network timeout communicating with a remote service.
    #[error("network timeout communicating with {peer}: elapsed {elapsed:?}")]
    NetworkTimeout {
        peer: String,
        elapsed: std::time::Duration,
    },

    /// I/O error reading or writing graph/route data.
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// FFI bridge error when communicating with Lean 4.
    #[error("Lean 4 FFI error: {0}")]
    FfiError(String),

    /// Graph serialization/deserialization failure.
    #[error("serialization error: {0}")]
    SerializationError(String),

    /// Generic routing error with context message.
    #[error("routing error: {0}")]
    Other(String),
}

/// Compile-time verification that `RouteError` implements `Send` + `Sync`.
#[allow(dead_code)]
const _: () = {
    fn assert_send_sync<T: Send + Sync>() {}
    fn _route_error_is_send_sync() {
        assert_send_sync::<RouteError>();
    }
};