use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
ZeroK,
BadBox,
Empty,
BufferSize,
Overflow,
MaskLen,
TooManyCells,
BadCutoff,
TooManyImages,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::ZeroK => write!(f, "k must be at least 1"),
Error::BadBox => write!(f, "singular or non-positive cell"),
Error::Empty => write!(f, "no points"),
Error::BufferSize => write!(f, "out buffer length must be n * k"),
Error::Overflow => write!(f, "n * k overflows"),
Error::MaskLen => write!(f, "mask length must be n"),
Error::TooManyCells => write!(f, "linked-cell mesh is too fine"),
Error::BadCutoff => write!(f, "cutoff must be finite and positive"),
Error::TooManyImages => write!(f, "periodic image count exceeds 2^24"),
}
}
}
impl std::error::Error for Error {}
impl From<minimage::Error> for Error {
fn from(err: minimage::Error) -> Self {
match err {
minimage::Error::BadBox => Error::BadBox,
minimage::Error::BufferSize => Error::BufferSize,
minimage::Error::Empty => Error::Empty,
}
}
}