1use std::error::Error;
2use std::fmt;
3
4#[derive(Clone, Debug, Eq, PartialEq)]
6pub enum IonValidationError {
7 EmptyName,
9 ZeroChargeMagnitude,
11 EmptyOxidationStateLabel,
13 ExpectedCation,
15 ExpectedAnion,
17 ExpectedMonatomicFormula,
19 ExpectedPolyatomicFormula,
21}
22
23impl fmt::Display for IonValidationError {
24 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::EmptyName => formatter.write_str("ion name must not be empty"),
27 Self::ZeroChargeMagnitude => {
28 formatter.write_str("ion charge magnitude must be greater than zero")
29 },
30 Self::EmptyOxidationStateLabel => {
31 formatter.write_str("oxidation-state label must not be empty")
32 },
33 Self::ExpectedCation => formatter.write_str("ion must have a positive charge"),
34 Self::ExpectedAnion => formatter.write_str("ion must have a negative charge"),
35 Self::ExpectedMonatomicFormula => {
36 formatter.write_str("ion formula must contain exactly one atom")
37 },
38 Self::ExpectedPolyatomicFormula => {
39 formatter.write_str("ion formula must contain more than one atom")
40 },
41 }
42 }
43}
44
45impl Error for IonValidationError {}