use std::{
error::Error,
fmt::{Display, Formatter},
};
use crate::{stage::ZeroStageError, Bell, IncompatibleStages, Stage};
#[allow(unused_imports)]
use crate::Row;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum InvalidRowError {
NoBells,
DuplicateBell(Bell),
BellOutOfStage(Bell, Stage),
MissingBell(Bell),
}
impl From<ZeroStageError> for InvalidRowError {
fn from(_: ZeroStageError) -> Self {
InvalidRowError::NoBells
}
}
impl Display for InvalidRowError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
InvalidRowError::DuplicateBell(bell) => {
write!(f, "bell '{}' appears twice.", bell)
}
InvalidRowError::BellOutOfStage(bell, stage) => {
write!(f, "bell '{}' is not within stage {}", bell, stage)
}
InvalidRowError::MissingBell(bell) => {
write!(f, "bell '{}' is missing", bell)
}
InvalidRowError::NoBells => write!(f, "row would have no bells"),
}
}
}
impl Error for InvalidRowError {}
#[derive(Debug, Copy, Clone)]
pub enum MulIntoError {
RhsStage(IncompatibleStages),
IntoStage(IncompatibleStages),
}
impl Display for MulIntoError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::RhsStage(IncompatibleStages {
lhs_stage,
rhs_stage,
}) => write!(f, "Can't multiply stage {} with {}", lhs_stage, rhs_stage),
Self::IntoStage(IncompatibleStages {
lhs_stage,
rhs_stage,
}) => write!(f, "Can't write stage {} into {}", lhs_stage, rhs_stage),
}
}
}
impl Error for MulIntoError {}