use std::error::Error;
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, PartialEq)]
pub enum MatchingError {
InvalidProbability {
probability: f64,
},
MissingEdge {
node1: usize,
node2: usize,
},
MissingBoundaryEdge {
node: usize,
},
InvalidInput(&'static str),
Upstream(String),
}
impl Display for MatchingError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidProbability { probability } => {
write!(
f,
"error probability must be within 0.0..=1.0, got {probability}"
)
}
Self::MissingEdge { node1, node2 } => {
write!(f, "edge ({node1}, {node2}) not in graph")
}
Self::MissingBoundaryEdge { node } => {
write!(f, "boundary edge ({node},) not in graph")
}
Self::InvalidInput(message) => f.write_str(message),
Self::Upstream(message) => f.write_str(message),
}
}
}
impl Error for MatchingError {}
pub type Result<T> = std::result::Result<T, MatchingError>;