1#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum MolParseError {
6 InvalidHeader { line: usize, detail: String },
8 InvalidCountLine { line: usize, detail: String },
10 InvalidAtomLine { line: usize, detail: String },
12 InvalidBondLine { line: usize, detail: String },
14 UnknownElement { symbol: String, line: usize },
16 UnexpectedEnd,
18 V3000ParseError { line: usize, msg: String },
20 Io(String),
22}
23
24impl std::fmt::Display for MolParseError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 Self::InvalidHeader { line, detail } => {
28 write!(f, "invalid header at line {line}: {detail}")
29 }
30 Self::InvalidCountLine { line, detail } => {
31 write!(f, "invalid counts line at line {line}: {detail}")
32 }
33 Self::InvalidAtomLine { line, detail } => {
34 write!(f, "invalid atom line at line {line}: {detail}")
35 }
36 Self::InvalidBondLine { line, detail } => {
37 write!(f, "invalid bond line at line {line}: {detail}")
38 }
39 Self::UnknownElement { symbol, line } => {
40 write!(f, "unknown element symbol '{symbol}' at line {line}")
41 }
42 Self::UnexpectedEnd => {
43 write!(f, "unexpected end of input")
44 }
45 Self::V3000ParseError { line, msg } => {
46 write!(f, "V3000 parse error at line {line}: {msg}")
47 }
48 Self::Io(msg) => write!(f, "IO error: {msg}"),
49 }
50 }
51}
52
53impl std::error::Error for MolParseError {}