1use core::fmt;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum Error {
12 AtomIndexOutOfRange {
14 index: u32,
16 num_atoms: u32,
18 },
19 SelfLoop {
21 atom: u32,
23 },
24 MolIndexOutOfRange {
26 index: u32,
28 num_mols: u32,
30 },
31 BondIndexOutOfRange {
33 index: u32,
35 num_bonds: u32,
37 },
38 BatchTooLarge {
40 what: &'static str,
42 count: usize,
44 },
45}
46
47impl fmt::Display for Error {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::AtomIndexOutOfRange { index, num_atoms } => {
51 write!(f, "原子下标 {index} 越界(共 {num_atoms} 个原子)")
52 }
53 Self::SelfLoop { atom } => {
54 write!(f, "原子 {atom} 上出现自环;分子图中不允许自环")
55 }
56 Self::BondIndexOutOfRange { index, num_bonds } => {
57 write!(f, "键下标 {index} 越界(共 {num_bonds} 条键)")
58 }
59 Self::MolIndexOutOfRange { index, num_mols } => {
60 write!(f, "分子下标 {index} 越界(共 {num_mols} 个分子)")
61 }
62 Self::BatchTooLarge { what, count } => {
63 write!(f, "批中 {what} 数量 {count} 超出 u32 索引上限")
64 }
65 }
66 }
67}
68
69impl std::error::Error for Error {}
70
71pub type Result<T> = core::result::Result<T, Error>;