use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
AtomIndexOutOfRange {
index: u32,
num_atoms: u32,
},
SelfLoop {
atom: u32,
},
MolIndexOutOfRange {
index: u32,
num_mols: u32,
},
BondIndexOutOfRange {
index: u32,
num_bonds: u32,
},
BatchTooLarge {
what: &'static str,
count: usize,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AtomIndexOutOfRange { index, num_atoms } => {
write!(f, "原子下标 {index} 越界(共 {num_atoms} 个原子)")
}
Self::SelfLoop { atom } => {
write!(f, "原子 {atom} 上出现自环;分子图中不允许自环")
}
Self::BondIndexOutOfRange { index, num_bonds } => {
write!(f, "键下标 {index} 越界(共 {num_bonds} 条键)")
}
Self::MolIndexOutOfRange { index, num_mols } => {
write!(f, "分子下标 {index} 越界(共 {num_mols} 个分子)")
}
Self::BatchTooLarge { what, count } => {
write!(f, "批中 {what} 数量 {count} 超出 u32 索引上限")
}
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;