1use std::error::Error;
2use std::fmt;
3
4#[derive(Clone, Debug, Eq, PartialEq)]
6pub enum MoleculeValidationError {
7 EmptyName,
9 MissingFormula,
11 EmptyAtomLabel,
13 InvalidAtomLabel(String),
15 EmptyAtomId,
17 ZeroConnectionOrder,
19 SelfConnection {
21 index: usize,
23 },
24 InvalidConnectionIndex {
26 index: usize,
28 atom_count: usize,
30 },
31}
32
33impl fmt::Display for MoleculeValidationError {
34 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 Self::EmptyName => formatter.write_str("molecule name must not be empty"),
37 Self::MissingFormula => formatter.write_str("molecule formula is required"),
38 Self::EmptyAtomLabel => formatter.write_str("atom label must not be empty"),
39 Self::InvalidAtomLabel(label) => write!(formatter, "invalid atom label: {label}"),
40 Self::EmptyAtomId => formatter.write_str("atom identifier must not be empty"),
41 Self::ZeroConnectionOrder => {
42 formatter.write_str("atom connection order must not be zero")
43 },
44 Self::SelfConnection { index } => {
45 write!(
46 formatter,
47 "atom connection cannot point index {index} to itself"
48 )
49 },
50 Self::InvalidConnectionIndex { index, atom_count } => write!(
51 formatter,
52 "atom connection index {index} is outside atom count {atom_count}"
53 ),
54 }
55 }
56}
57
58impl Error for MoleculeValidationError {}