use crate::error::LocalIjError;
use core::{error::Error, fmt};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InvalidGeometry {
reason: &'static str,
}
impl InvalidGeometry {
pub(crate) const fn new(reason: &'static str) -> Self {
Self { reason }
}
}
impl fmt::Display for InvalidGeometry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.reason)
}
}
impl Error for InvalidGeometry {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum PlotterError {
InvalidGeometry(InvalidGeometry),
LocalIj(LocalIjError),
}
impl fmt::Display for PlotterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::InvalidGeometry(err) => write!(f, "plotting error: {err}"),
Self::LocalIj(err) => write!(f, "plotting error: {err}"),
}
}
}
impl Error for PlotterError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Self::InvalidGeometry(ref err) => Some(err),
Self::LocalIj(ref err) => Some(err),
}
}
}
impl From<InvalidGeometry> for PlotterError {
fn from(value: InvalidGeometry) -> Self {
Self::InvalidGeometry(value)
}
}
impl From<LocalIjError> for PlotterError {
fn from(value: LocalIjError) -> Self {
Self::LocalIj(value)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DissolutionError {
UnsupportedResolution,
DuplicateInput,
}
impl fmt::Display for DissolutionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::UnsupportedResolution => {
write!(f, "unsupported resolution")
}
Self::DuplicateInput => write!(f, "duplicate indices"),
}
}
}
impl Error for DissolutionError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}