use crate::util::block_count::BlockCountMismatch;
#[derive(Clone, Debug)]
pub enum SmoothError {
InvalidConfig { reason: String },
DimensionMismatch { reason: String },
InvalidIndex { reason: String },
}
impl std::fmt::Display for SmoothError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SmoothError::InvalidConfig { reason }
| SmoothError::DimensionMismatch { reason }
| SmoothError::InvalidIndex { reason } => f.write_str(reason),
}
}
}
impl std::error::Error for SmoothError {}
impl From<SmoothError> for String {
fn from(err: SmoothError) -> String {
err.to_string()
}
}
impl From<BlockCountMismatch> for SmoothError {
fn from(err: BlockCountMismatch) -> SmoothError {
SmoothError::invalid_index(err.message())
}
}
impl SmoothError {
#[inline]
pub(super) fn invalid_config(reason: impl Into<String>) -> Self {
SmoothError::InvalidConfig {
reason: reason.into(),
}
}
#[inline]
pub(super) fn dimension_mismatch(reason: impl Into<String>) -> Self {
SmoothError::DimensionMismatch {
reason: reason.into(),
}
}
#[inline]
pub(super) fn invalid_index(reason: impl Into<String>) -> Self {
SmoothError::InvalidIndex {
reason: reason.into(),
}
}
}