use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum PgmError {
VariableNotFound(String),
FactorNotFound(String),
DimensionMismatch {
expected: Vec<usize>,
got: Vec<usize>,
},
InvalidDistribution(String),
ConvergenceFailure(String),
InvalidGraph(String),
}
impl fmt::Display for PgmError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::VariableNotFound(name) => write!(f, "Variable not found: {}", name),
Self::FactorNotFound(name) => write!(f, "Factor not found: {}", name),
Self::DimensionMismatch { expected, got } => {
write!(
f,
"Dimension mismatch: expected {:?}, got {:?}",
expected, got
)
}
Self::InvalidDistribution(msg) => write!(f, "Invalid distribution: {}", msg),
Self::ConvergenceFailure(msg) => write!(f, "Convergence failure: {}", msg),
Self::InvalidGraph(msg) => write!(f, "Invalid graph: {}", msg),
}
}
}
impl std::error::Error for PgmError {}
pub type Result<T> = std::result::Result<T, PgmError>;