use_oxidation_state/
error.rs1use std::error::Error;
2use std::fmt;
3
4#[derive(Clone, Debug, Eq, PartialEq)]
6pub enum OxidationStateValidationError {
7 ZeroSignedMagnitude,
9 NonZeroZeroMagnitude,
11 MagnitudeAboveMaximum { magnitude: u8, maximum: u8 },
13 EmptyAssignmentLabel,
15 EmptyElementSymbol,
17 InvalidElementSymbol(String),
19 EmptyFormulaLabel,
21}
22
23impl fmt::Display for OxidationStateValidationError {
24 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::ZeroSignedMagnitude => {
27 formatter.write_str("signed oxidation-state magnitude must be greater than zero")
28 },
29 Self::NonZeroZeroMagnitude => {
30 formatter.write_str("zero oxidation state must have zero magnitude")
31 },
32 Self::MagnitudeAboveMaximum { magnitude, maximum } => write!(
33 formatter,
34 "oxidation-state magnitude {magnitude} is greater than maximum {maximum}"
35 ),
36 Self::EmptyAssignmentLabel => {
37 formatter.write_str("oxidation-state assignment label must not be empty")
38 },
39 Self::EmptyElementSymbol => formatter.write_str("element symbol must not be empty"),
40 Self::InvalidElementSymbol(symbol) => {
41 write!(formatter, "invalid element symbol: {symbol}")
42 },
43 Self::EmptyFormulaLabel => {
44 formatter.write_str("formula oxidation-state label must not be empty")
45 },
46 }
47 }
48}
49
50impl Error for OxidationStateValidationError {}