use core::fmt;
use std::io;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Custom(String),
MeshGeneration(String),
Deformation(String),
FileSystem(io::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Custom(msg) => write!(f, "🔴 Error: {msg}"),
Error::MeshGeneration(msg) => write!(f, "🔴 Mesh generation error: {msg}"),
Error::Deformation(msg) => write!(f, "🔴 Deformation error: {msg}"),
Error::FileSystem(err) => write!(f, "🔴 IO error: {err}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Custom(_) => None,
Error::MeshGeneration(_) => None,
Error::Deformation(_) => None,
Error::FileSystem(err) => Some(err),
}
}
}
impl From<&str> for Error {
fn from(value: &str) -> Self {
Self::Custom(value.to_string())
}
}
impl From<String> for Error {
fn from(value: String) -> Self {
Self::Custom(value)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::FileSystem(err)
}
}