use std::error::Error;
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OxidationStateValidationError {
ZeroSignedMagnitude,
NonZeroZeroMagnitude,
MagnitudeAboveMaximum { magnitude: u8, maximum: u8 },
EmptyAssignmentLabel,
EmptyElementSymbol,
InvalidElementSymbol(String),
EmptyFormulaLabel,
}
impl fmt::Display for OxidationStateValidationError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroSignedMagnitude => {
formatter.write_str("signed oxidation-state magnitude must be greater than zero")
},
Self::NonZeroZeroMagnitude => {
formatter.write_str("zero oxidation state must have zero magnitude")
},
Self::MagnitudeAboveMaximum { magnitude, maximum } => write!(
formatter,
"oxidation-state magnitude {magnitude} is greater than maximum {maximum}"
),
Self::EmptyAssignmentLabel => {
formatter.write_str("oxidation-state assignment label must not be empty")
},
Self::EmptyElementSymbol => formatter.write_str("element symbol must not be empty"),
Self::InvalidElementSymbol(symbol) => {
write!(formatter, "invalid element symbol: {symbol}")
},
Self::EmptyFormulaLabel => {
formatter.write_str("formula oxidation-state label must not be empty")
},
}
}
}
impl Error for OxidationStateValidationError {}