use comp_cat_rs::collapse::free_category::FreeCategoryError;
#[derive(Debug)]
pub enum Error {
FreeCategory(FreeCategoryError),
WireOutOfBounds {
wire_index: usize,
allocated: usize,
},
WireCountMismatch {
expected: usize,
actual: usize,
},
DivisionByZero,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::FreeCategory(e) => write!(f, "free category error: {e}"),
Self::WireOutOfBounds {
wire_index,
allocated,
} => write!(
f,
"wire index {wire_index} out of bounds (allocated: {allocated})"
),
Self::WireCountMismatch { expected, actual } => {
write!(f, "wire count mismatch: expected {expected}, got {actual}")
}
Self::DivisionByZero => write!(f, "division by zero"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::FreeCategory(e) => Some(e),
Self::WireOutOfBounds { .. }
| Self::WireCountMismatch { .. }
| Self::DivisionByZero => None,
}
}
}
impl From<FreeCategoryError> for Error {
fn from(e: FreeCategoryError) -> Self {
Self::FreeCategory(e)
}
}