#![deny(missing_docs)]
#![warn(rust_2018_idioms)]
#![forbid(unsafe_code)]
#[cfg(feature = "operator")]
pub mod op_dag_graph;
#[cfg(feature = "operator")]
pub mod sheaf_partitioner;
#[cfg(all(feature = "graph", feature = "operator"))]
pub mod witness_bridge;
#[cfg(all(feature = "graph", feature = "operator"))]
pub mod cad_bridge;
#[cfg(all(feature = "graph", feature = "operator"))]
pub mod lean_proof_bridge;
#[cfg(all(feature = "llm", feature = "operator"))]
pub mod llm_bridge;
#[cfg(all(feature = "graph", feature = "operator"))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BridgeError {
Unsupported(String),
Upstream(String),
Io(String),
Context {
source: Box<BridgeError>,
context: String,
},
}
#[cfg(all(feature = "graph", feature = "operator"))]
impl BridgeError {
pub fn with_context(self, ctx: impl Into<String>) -> Self {
Self::Context {
source: Box::new(self),
context: ctx.into(),
}
}
}
#[cfg(all(feature = "graph", feature = "operator"))]
impl std::fmt::Display for BridgeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Unsupported(msg) => write!(f, "unsupported bridge input: {msg}"),
Self::Upstream(msg) => write!(f, "upstream error: {msg}"),
Self::Io(msg) => write!(f, "io error: {msg}"),
Self::Context { source, context } => write!(f, "{context}: {source}"),
}
}
}
#[cfg(all(feature = "graph", feature = "operator"))]
impl std::error::Error for BridgeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Context { source, .. } => Some(source.as_ref()),
_ => None,
}
}
}
#[cfg(all(test, feature = "graph", feature = "operator"))]
mod bridge_error_tests {
use super::BridgeError;
#[test]
fn context_wraps_underlying() {
let inner = BridgeError::Upstream("header malformed".into());
let outer = inner.with_context("while loading model 'foo.safetensors'");
match &outer {
BridgeError::Context { source, context } => {
assert_eq!(context, "while loading model 'foo.safetensors'");
assert!(matches!(source.as_ref(), BridgeError::Upstream(_)));
}
_ => panic!("expected Context variant"),
}
let chain: String = outer.to_string();
assert!(chain.contains("loading model"));
assert!(chain.contains("header malformed"));
}
}